首先看一下最终效果,在终端模式下实现类似于聊天的对话框 实现方式如下,通过两个list: iwords和swords分别缓存来自终端输入和socket收到的数据,然后再将数据通过屏幕输出并通过socket接口发送出去,通过四个独立的线程分别完成各自的工作: myinput:获取输入区域内的输入数据,并将数据append到iwords和swords myoutput:检测swords长度并通过swo […]
月度归档: 2017 年 6 月
试用python的curses模块创建window
实现效果如下图,在console的上部分显示输入的内容,下部分用于输入: 虽然比较粗糙,但是一般的功能勉强可用了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#!/usr/bin/env python import curses import curses.textpad stdscr = curses.initscr() #通过string来存储输入的内容,每次换行后显示 words = '' def mywin(): global words #创建两个win窗口,stdwin用来输入,stdwin2用来输出 #newwin(行数,列数,y坐标,x坐标) stdwin = curses.newwin(1,curses.COLS,curses.LINES-1,0) stdwin2 = curses.newwin(1000, curses.COLS, 0, 0) lines = 0 while True: stdwin.addstr('>') stdwin.refresh() while True: k = stdwin.getkey() if k != '\n': words += k else: stdwin2.addstr(words + '\n') stdwin2.refresh() lines += int(len(words) / curses.COLS) + 1 if lines >= curses.LINES-2: stdwin2.clear() lines = int(len(words) / curses.COLS) + 1 words='' stdwin.clear() break try: mywin() except Exception: raise Exception finally: curses.endwin() |
已知问题: 1.输入后不能使用backspace或者delete进行删除,方向键等功能键也会被直接识别为键值,而不是执行对应的功能(删除可以用Ctrl+Backspace,但是屏幕不会刷新被删除的内容) 2.输出窗口的行 […]
ubuntu17.04解决rtl8188cus无线网卡无法链接问题
自从ubuntu升级之后,EDUP无线网卡总是无法正常链接wifi,dmesg里面提示“ing authentication with *** by local choice (Reason: 3=DEAUTH_LEAVING)”的错误,搜索错误信息也找不到有用的内容 不得已用pi作中转先凑合着用,但是这样总归是比较麻烦。恰好这几天有闲功夫,google看是否有解决的办法,由于上面的错误信息没有可 […]
ubuntu upgrade忽略特定的包
例如设置下面两个包在apt-get upgrade的时候不升级: echo wine-staging-amd64 hold | sudo dpkg --set-selections echo wine-staging-i386 hold | sudo dpkg --set-selections 取消则将hold换为install: echo wine-staging-amd64 install | […]