lemonbar: temp fixes

lemonbar: temp
This commit is contained in:
kuben
2019-09-19 08:32:03 +02:00
parent 2f31eef54b
commit a86415f264
3 changed files with 54 additions and 67 deletions

View File

@@ -1,5 +1,7 @@
import threading
import subprocess
import contextlib
import os, getpass
import i3_lemonbar_config as config
import i3_lemonbar_common as common
@@ -357,14 +359,25 @@ class i3Module(LemonModule):
subprocess.call(['/home/kuba/.i3/scripts/lang.sh', 'qset', new_km])
class ScreenModule(LemonModule):
# Start, stop and send commands to screen instance
# Start detached, in UTF-8 mode. Log to fifo
start_flags = ['-d', '-m', '-U', '-L', '-Logfile', config.fifo_screen_log]
def __init__(self):
self.prefix = 'RESP'
self.prefix = ''
super().__init__()
def _start_module(self):
# No external commands needed
self.status_handle = None
self.identifier = 'lemonbar_{}_{}'.format(getpass.getuser(), os.getpid())
self.empty_count = 0
common.screen_send_cmd = self.send_cmd
common.create_new_fifo(config.fifo_screen_log)
self.send(self.start_flags) # Start screen
self.send_cmd('stty -echo') # Do not echo what is written to screen terminal
self.send_colon('logfile flush 0.1') # Log quickly
self.status_handle = open(config.fifo_screen_log, 'r', buffering=1)
self.controls = parser.ButtonsUnit('controls', order=-10)
self.response = parser.IconTextUnit('response', order=10)
@@ -385,11 +398,42 @@ class ScreenModule(LemonModule):
parser.g_parser.register_unit(self.controls)
def _stop_module(self):
self.send_colon('kill')
self.status_handle.close()
with contextlib.suppress(FileNotFoundError):
os.remove(config.fifo_screen_log)
parser.g_parser.remove_unit(self.response)
parser.g_parser.remove_unit(self.controls)
def _parse_data(self, data):
self.response.items = [('', ' '.join(data))]
line = ' '.join(data)
line = common.strip_ansi_unicode(line)
common.logger.debug('Screen read line {}'.format(line))
if (not line.startswith('[CHG]')
and not line.isspace()):
self.response.items = [('', line)]
if not line:
# End loop if many empty lines in a row
self.empty_count = self.empty_count + 1
if self.empty_count > 3:
common.logger.error('Too many empty lines, aborting')
# TODO actually abort
else:
self.empty_count = 0
def send(self, args):
# Send something to our screen instance
subprocess.call(['screen', '-S', self.identifier] + args)
def send_cmd(self, cmd):
# Send terminal input to our screen instance
self.send(['-X', 'stuff', cmd + '\n'])
def send_colon(self, cmd):
# Send colon command to our screen instance
self.send(['-X', 'colon', cmd + '\n'])
class PowerOptionsModule(LemonModule):