Skip to content

Commit 7f92707

Browse files
author
mirkobrombin
committed
support custom palette on call
1 parent 97c0b41 commit 7f92707

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

easyterm/easyterm.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@
1616
CONF_BG = Gdk.RGBA(0.1, 0.1, 0.1, 1.0)
1717

1818
class Terminal(Vte.Terminal):
19-
def __init__(self, *args, **kwds):
19+
def __init__(self, palette=None, *args, **kwds):
2020
super(Terminal, self).__init__(*args, **kwds)
2121
self.set_cursor_blink_mode(Vte.CursorBlinkMode.ON)
2222
self.set_mouse_autohide(True)
2323
self.set_font(Pango.FontDescription(CONF_FONT))
24-
self.set_colors(
25-
foreground=CONF_FG,
26-
background=CONF_BG,
27-
)
24+
if palette is None or len(palette) < 2:
25+
self.set_colors(
26+
foreground=CONF_FG,
27+
background=CONF_BG,
28+
)
29+
else:
30+
self.set_colors(
31+
foreground=palette[0],
32+
background=palette[1],
33+
)
2834

2935
def run_command(self, cmd):
3036
_cmd = str.encode(f"{cmd}\n")
@@ -59,8 +65,6 @@ def build_actions(self, actions:dict):
5965
class MainWindow(Handy.ApplicationWindow):
6066
Handy.init()
6167
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
62-
terminal = Terminal()
63-
headerbar = HeaderBar(terminal)
6468

6569
def __init__(
6670
self,
@@ -69,12 +73,16 @@ def __init__(
6973
env:list=[],
7074
actions:list=[],
7175
dark_theme:bool=False,
76+
palette:list=[],
7277
*args, **kwds
7378
):
7479
super().__init__()
7580
self.set_title(CONF_NAME)
7681
self.set_default_size(800, 450)
7782

83+
self.terminal = Terminal(palette)
84+
self.headerbar = HeaderBar(self.terminal)
85+
7886
if dark_theme:
7987
self.set_dark_theme()
8088

@@ -121,9 +129,10 @@ def __init__(
121129
env:list=[],
122130
actions:list=[],
123131
dark_theme:bool=False,
132+
palette:list=[],
124133
*args, **kwds
125134
):
126-
self.window = MainWindow(cwd, command, env, actions, dark_theme)
135+
self.window = MainWindow(cwd, command, env, actions, dark_theme, palette)
127136
self.window.show_all()
128137
self.window.connect("delete-event", Gtk.main_quit)
129138
Gtk.main()
@@ -191,6 +200,14 @@ def __register_arguments(self):
191200
"Set the dark theme",
192201
None
193202
)
203+
self.add_main_option(
204+
"palette",
205+
ord("p"),
206+
GLib.OptionFlags.NONE,
207+
GLib.OptionArg.STRING,
208+
"Set the palette (RGBA_back, RGBA_fore)",
209+
None
210+
)
194211

195212

196213
def do_command_line(self, command_line):
@@ -199,22 +216,32 @@ def do_command_line(self, command_line):
199216
env = []
200217
actions = []
201218
dark_theme = False
219+
palette = []
202220

203221
options = command_line.get_options_dict()
204222

205223
if options.contains("cwd"):
206224
cwd = options.lookup_value("cwd").get_string()
207225
if options.contains("command"):
208226
command = shlex.split(options.lookup_value("command").get_string())
209-
210227
if options.contains("env"):
211228
env = options.lookup_value("env").get_string().split(" ")
212229
if options.contains("actions"):
213230
actions = options.lookup_value("actions").get_string().split(" ")
214231
if options.lookup_value("dark-theme").get_boolean():
215232
dark_theme = True
233+
if options.contains("palette"):
234+
palette = options.lookup_value("palette").get_string().split(" ")
235+
if len(palette) < 2:
236+
palette = []
237+
else:
238+
back = Gdk.RGBA()
239+
back.parse(palette[0])
240+
fore = Gdk.RGBA()
241+
fore.parse(palette[1])
242+
palette = [back, fore]
216243

217-
EasyTermLib(cwd, command, env, actions, dark_theme)
244+
EasyTermLib(cwd, command, env, actions, dark_theme, palette)
218245
return 0
219246

220247
def do_activate(self):

0 commit comments

Comments
 (0)