curses

Python curses.getmouse()

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: #!/usr/bin/env python # -*- coding: utf-8 -*- import curses screen = curses.initscr() curses.noecho() curses.curs_set(0) screen.keypad(1) curses.mousemask(1) screen.addstr("This is a Sample Curses Script\n\n") while True: event = screen.getch() if event == ord("q"): break if event == curses.KEY_MOUSE: screen.addstr(curses.getmouse()) curses.endwin() if event == curses.KEY_MOUSE: screen.addstr(curses.getmouse()) I think I should get the text where mouse is clicked or not? All I get is TypeError: str . Why is that? What am I missing? I couldn

Python Curses Handling Window (Terminal) Resize

徘徊边缘 提交于 2019-12-03 04:38:07
This is two questions really: how do I resize a curses window, and how do I deal with a terminal resize in curses? Is it possible to know when a window has changed size? I really can't find any good doc, not even covered on http://docs.python.org/library/curses.html Terminal resize event will result in the curses.KEY_RESIZE key code. Therefore you can handle terminal resize as part of a standard main loop in a curses program, waiting for input with getch . jarsever I got my python program to re-size the terminal by doing a couple of things. # Initialize the screen import curses screen = curses

How to create a menu and submenus in Python curses?

天涯浪子 提交于 2019-12-03 04:24:53
问题 AFAIK, there is no curses menu extension available in Python yet so you have to roll your own solution. I know about this patch http://bugs.python.org/issue1723038 but I don't what's the current state of it. I found a nice class for Python that wraps what I want called 'cmenu' here http://www.promisc.org/blog/?p=33 but I have a problem with that too. I want to make a menu where user can choose a highlighted element but instead of executing a particular action right away I want to display

How to use terminal color palette with curses

China☆狼群 提交于 2019-12-03 02:22:01
问题 I can't get the terminal color palette to work with curses. import curses def main(stdscr): curses.use_default_colors() for i in range(0,7): stdscr.addstr("Hello", curses.color_pair(i)) stdscr.getch() curses.wrapper(main) This python script yields the following screen: However, I do have more colors in my gnome-terminal palette. How can I access them within curses? 回答1: The following I figured out by experiment on my own pc (Ubuntu 14.04, python 3). There are 256 colors (defined by the first

Error no module named curses

匿名 (未验证) 提交于 2019-12-03 02:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I try to run the following code... from telnetsrvlib import * if __name__ == '__main__': "Testing - Accept a single connection" class TNS(SocketServer.TCPServer): allow_reuse_address = True class TNH(TelnetHandler): def cmdECHO(self, params): """ [ ...] Echo parameters Echo command line parameters back to user, one per line. """ self.writeline("Parameters:") for item in params: self.writeline("\t%s" % item) def cmdTIME(self, params): """ Print Time Added by dilbert """ self.writeline(time.ctime()) logging.getLogger('').setLevel(logging

ncurses键盘管理:cbreak,keypad,getch(),KEY_F(),clrtoeol()

匿名 (未验证) 提交于 2019-12-03 00:32:02
Copyright(C) NCURSES Programming HOWTO 键盘管理 基础知识 每一个GUI(图形用户界面)都有强大的用户交互界面。一个curses 程序应该对用户的输入(仅通过键盘和鼠标)及时的做出反应。那就让我们从处理键盘开始。就像前面章节中的例子那样,很容易就能取得用户的输入。一个最简单的方法是使用 getch() 函数。如果你喜欢处理单个按键,而不是处理一行的话(经常以回车键作为一行结束标志),你应该在读取按键之前激活 cbreak 模式。如果要读取功能键则应该激活 keypad getch() 返回一个整数来对应键盘上的按键。如果你输入的是一个普通字符,这个整数就等价于该字符。如果是其它字符,它就返回一个在 curses.h F1 ,返回的整数将是 265 ,该值可以通过 curses.h KEY_F() 检测。这样可以更方便的管理键盘的输入。 例如,如果你这样调用 getch() 函数: int ch; ch = getch(); getch() curses.h 中找到。 以下这段代码就可以用来监测键盘左方向键: if (ch == KEY_LEFT) printw ( " Left arrow is pressed \n " ); 让我们写一个可以通过上下键操纵的窗口菜单。 一个简单的使用键盘的例子 例: 一个读取键盘的例子 /* Compile:

ncurses初始化函数:raw(),cbreak(),echo(),noecho(),keypad(),halfdelay()

匿名 (未验证) 提交于 2019-12-03 00:32:02
NCURSES Programming HOWTO 初始化函数 我们现在知道在程序中调用 initscr() 函数,屏幕就会初始化并进入curses 模式。本章我们会介绍其它的初始化函数,这些函数可以根据我们自己的要求在初始化后定制curses 会话(curses session)的功能及模式。例如: 终端模式 (terminal mode)、 彩色显示模式 (colormode)、 鼠标操作模式 (mouse mode)等。当然,我们还可以定制 混合模式 。这章就让我们来讨论这些在 initscr() 函数之后调用的初始化函数。 raw() 函数和 cbreak() 函数 通常情况下,终端驱动程序会缓冲用户输入的字符,直到遇到换行符或回车符后,这些字符才可以被使用。但是大多数程序要求字符在输入时就可以被使用。 raw() 和 cbreak() 两个函数都可以禁止行缓冲(line buffering)。 区别 是:在 raw() 函数模式下,处理挂起(CTRLZ)、中断或退出(CTRLC)等控制字符时,将直接传送给程序去处理而不产生终端信号;而在 cbreak() 模式下,控制字符将被终端驱动程序解释成其它字符。就我个人而言,比较喜欢使用 raw() 函数,因为用它可以做一些一般用户无法进行的控制操作。 echo() 函数和 noecho() 函数

Python issue with curses.intscr()

时光毁灭记忆、已成空白 提交于 2019-12-02 17:18:02
问题 I am new in Python and I am using curses for my script. But when I am try to run the script in server(let say 1) I am getting below error. _curses.error: addstr() returned ERR And the same script when I am try to run in another server(let say 2) it is running successfully. The reason is server 1 is producing more data to display on screen and server 1 is producing less data to display on screen. So while searching found that curses.intscr() getting the screen size fixed and that's why it is

How to use terminal color palette with curses

与世无争的帅哥 提交于 2019-12-02 15:53:28
I can't get the terminal color palette to work with curses. import curses def main(stdscr): curses.use_default_colors() for i in range(0,7): stdscr.addstr("Hello", curses.color_pair(i)) stdscr.getch() curses.wrapper(main) This python script yields the following screen: However, I do have more colors in my gnome-terminal palette. How can I access them within curses? The following I figured out by experiment on my own pc (Ubuntu 14.04, python 3). There are 256 colors (defined by the first 8 bits). The other bits are used for additional attributes, such as highlighting. Passing the number -1 as

Importing a Swift module using a C library

只谈情不闲聊 提交于 2019-12-02 13:41:25
问题 I've written a Curses wrapper module by following the instructions of this page. However, I do not know how to properly make it work in a module using it. I have 3 parallel directories: CCurses, CursesWrapper, ModuleUsingCursesWrapper. CCurses contains an empty Package.swift file and a module.modulemap file containing module CCurses [system] { header "/usr/include/curses.h" link "curses" export * } CursesWrapper contains a Package.swift file containing. import PackageDescription let package =