diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-07-21 23:18:56 +0200 | 
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-07-21 23:18:56 +0200 | 
| commit | 611b0fbd9c0e55b0649340563a63434cf51c5adf (patch) | |
| tree | b0c9d297c75365e47b3c1ed2c2e34c952f48e890 | |
| parent | add timezone support (diff) | |
| download | xpybar-611b0fbd9c0e55b0649340563a63434cf51c5adf.tar.gz xpybar-611b0fbd9c0e55b0649340563a63434cf51c5adf.tar.bz2 xpybar-611b0fbd9c0e55b0649340563a63434cf51c5adf.tar.xz  | |
ropty, does not work with the standard programs, but you can echo into it
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
| -rw-r--r-- | DEPENDENCIES | 1 | ||||
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | TODO | 1 | ||||
| -rw-r--r-- | examples/plugins/ropty | 30 | ||||
| -rw-r--r-- | src/plugins/ropty.py | 113 | 
5 files changed, 146 insertions, 3 deletions
diff --git a/DEPENDENCIES b/DEPENDENCIES index 7b43bbb..31835c2 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -13,6 +13,7 @@ OPTIONAL RUNTIME DEPENDENCIES:  	python-pyalsaaudio: for ALSA volume control  	hdparm: for hdparm support  	python-pytz: for timezone support +	python-sysv-ipc: for ropty example  BUILD DEPENDENCIES: @@ -32,12 +32,12 @@ PLUGINS = chase clock cpuinfo cpuonline cpu df discstats ipaddress  \            kmsg leapsec linereader loadavg lunar mem moc network     \            pacman snmp snmp6 softirqs solar uname uptime users       \            vmstat weather xdisplay xkb alsa dentrystate inodestate   \ -          files hdparm tzclock +          files hdparm tzclock ropty  PLUGIN_EXAMPLES = chase clock cpu cpuinfo cpuonline df discstats   \                    ipaddress kmsg loadavg lunar mem moc network     \                    pacman uname uptime users xdisplay xkb alsa      \ -                  dentrystate inodestate files tzclock +                  dentrystate inodestate files tzclock ropty  EXAMPLES = mixed moderate test xmonad @@ -20,7 +20,6 @@ List of plugins to implement:       Keyboard layout       EWMH       Meteor showers -     pty for write/talk messages       Lunar and solar eclipses       e-mail       Identify active and visible windows diff --git a/examples/plugins/ropty b/examples/plugins/ropty new file mode 100644 index 0000000..5e41351 --- /dev/null +++ b/examples/plugins/ropty @@ -0,0 +1,30 @@ +# -*- python -*- + +# A xpybar configuration example testing the features of plugins.kmsg + +from plugins.ropty import ROPTY + + +OUTPUT, HEIGHT, YPOS, TOP = 0, 12, 24, True + +text = '' +pty_ = None + +start_ = start +def start(): +    global pty_ +    start_() +    def refresh(): +        if pty_.size() == 0: +            text = '' +        else: +            line = pty_.next +            text = '\033[37;41m%i\033[00m%s' +            text %= (pty_.size(), line) +        bar.invalidate() +    pty_ = ROPTY(refresh) + +def redraw(): +    bar.clear() +    bar.draw_coloured_text(0, 10, 0, 2, text) + diff --git a/src/plugins/ropty.py b/src/plugins/ropty.py new file mode 100644 index 0000000..09e4a23 --- /dev/null +++ b/src/plugins/ropty.py @@ -0,0 +1,113 @@ +# -*- python -*- +''' +xpybar – xmobar replacement written in python +Copyright © 2014  Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program.  If not, see <http://www.gnu.org/licenses/>. +''' +import os +import threading + +from plugins.linereader import LineReader + + +class ROPTY(LineReader): +    ''' +    Read-only PTY for viewing of wall, write and talk messages +     +    @variable  on_update:()→void  Called when a new line is available +    @variable  master:int         The file descriptor of the PTY master +    @variable  slave:int          The file descriptor of the PTY slave +    ''' +     +     +    def __init__(self, on_update = None): +        ''' +        Constructor +         +        @param  on_update:()→void  Called when a new line is available +        ''' +        def noop(): +            pass +        self.on_update = noop if on_update is None else on_update +        (self.master, self.slave) = os.openpty() +        self.__reader = LineReader(self.master) +        self.__condition = threading.Condition() +        self.__queue = [] +        def background(): +            try: +                while True: +                    got = self.__reader.next() +                    if got is None: +                        return +                    self.__condition.acquire() +                    try: +                        self.__queue.append(got) +                    finally: +                        self.__condition.release() +                    self.on_update() +            except: +                return +        self.__thread = threading.Thread(target = background) +        self.__thread.setDaemon(True) +        self.__thread.start() +     +     +    def close(self): +        ''' +        Close the PTY +        ''' +        os.close(self.slave) +        os.close(self.master) +     +     +    def size(self): +        ''' +        Return the number of available lines +         +        @return  :int  The number of available lines +        ''' +        self.__condition.acquire() +        try: +            return len(self.__queue) +        finally: +            self.__condition.release() +     +     +    def __len__(self): +        ''' +        Return the number of available lines +         +        @return  :int  The number of available lines +        ''' +        return self.size() +     +     +    def next(self): +        ''' +        Return and unqueue the next available line +         +        @return  :str  The next available line, `None` if there +                       are no more lines currently available +        ''' +        self.__condition.acquire() +        try: +            if len(self.__queue) == 0: +                return None +            rc = self.__queue[0] +            self.__queue[:] = self.__queue[1:] +        finally: +            self.__condition.release() +        return rc +  | 
