2

How to work with terminal window in mode when it is possible to operate with each cell by it coords? I dont know how this mode named, thats why I cant google it. Also, I know about this approach, but now it is interesting for me how to work with it low level.

UPD: Ok, I read all the termios man page and some other docs, and the only thing I could say now - I still dont know how to make rotating bar somewhere in the terminal, ie by frames: - \ | / - .:(

UPD2 Oh, I suddenly found it there:

import sys
import time

f='-\\|/'

for i in range(10):
    sys.stdout.write("\r{0}".format(f[i%4]))
    sys.stdout.flush()
    time.sleep(0.5)

So, the last question in this topic - what about any coordinates only with termios?

Subquestion[SOLVED]:

When I use curses ie the second code listing from this post - it makes my semi-transparent terminal window no-transparent, when top does not do this. How to keep it transparent?

solution: insert curses.use_default_colors() in the first string of def pbar(window):.

Community
  • 1
  • 1
scythargon
  • 3,363
  • 3
  • 32
  • 62
  • you may want to mention operating system...since it will change significantly depending on which OS you are using (NO portability...) – Joran Beasley Aug 06 '12 at 22:16
  • @JoranBeasley of course it is linux (ubuntu 12.04), does windows users know the word 'terminal'?:) – scythargon Aug 06 '12 at 23:44

2 Answers2

1

curses ( http://docs.python.org/library/curses.html ) or Console ( http://effbot.org/zone/console-handbook.htm ) modules are what you want

the source of Console.py is available here http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/pylibs/readline/Console.py Im sure you could look at that... although Im sure its probably a big pain and thats why people always use curses...

On windows you may want to browse msdn http://msdn.microsoft.com/en-us/library/system.console.aspx and call it using ctypes.cdll.whatever

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • no, dude, did you read this - "I know about this approach, but now it is interesting for me how to work with it low level"? Im asking about something like termios.tcgetattr()! – scythargon Aug 06 '12 at 21:53
  • I think you will need to use ctypes for that... not sure ... its a big pain I think...the source of Console.py is available here http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/pylibs/readline/Console.py Im sure you could look at that... – Joran Beasley Aug 06 '12 at 22:01
  • wow, it is too hardcore:))) _still looking for simple example_ – scythargon Aug 06 '12 at 22:08
0

If you want a lower level library than curses, you can use termios (although I would suspect htop's UI is written mainly with curses)

The Python docs page on termios are minimal as the module pretty much just exposes the underlying UNIX'y termios library, so non-Python-specific docs are the main source of information, like this guide on termios, or the termios.h header (or run man termios in a shell)

Of course the challenge is translating the code into Python, but usually the translation is reasonably straight forward (the function calls are usually very similar, and the bit-swizzling/bit-masking is often identical)

dbr
  • 165,801
  • 69
  • 278
  • 343