Exemplo n.º 1
0
def set_default_colors(fg=None, bg=None):
    ans = ''
    if fg is None:
        ans += '\x1b]110\x1b\\'
    else:
        ans += '\x1b]10;{}\x1b\\'.format(color_as_sharp(fg if isinstance(fg, Color) else to_color(fg)))
    if bg is None:
        ans += '\x1b]111\x1b\\'
    else:
        ans += '\x1b]11;{}\x1b\\'.format(color_as_sharp(bg if isinstance(bg, Color) else to_color(bg)))
    return ans
Exemplo n.º 2
0
 def item(which: Optional[Union[Color, str]], num: int) -> None:
     nonlocal ans
     if which is None:
         ans += '\x1b]1{}\x1b\\'.format(num)
     else:
         if isinstance(which, Color):
             q = color_as_sharp(which)
         else:
             x = to_color(which)
             assert x is not None
             q = color_as_sharp(x)
         ans += '\x1b]{};{}\x1b\\'.format(num, q)
Exemplo n.º 3
0
 def item(which, num):
     nonlocal ans
     if which is None:
         ans += '\x1b]1{}\x1b\\'.format(num)
     else:
         ans += '\x1b]{};{}\x1b\\'.format(
             num,
             color_as_sharp(
                 which if isinstance(which, Color) else to_color(which)))
Exemplo n.º 4
0
def colors_as_escape_codes(o: KittyOptions) -> str:
    ans = set_default_colors(fg=o.foreground,
                             bg=o.background,
                             cursor=o.cursor,
                             select_bg=o.selection_background,
                             select_fg=o.selection_foreground)
    cmds = []
    for i in range(256):
        col = color_as_sharp(color_from_int(o.color_table[i]))
        cmds.append(f'{i};{col}')
    return ans + '\033]4;' + ';'.join(cmds) + '\033\\'
Exemplo n.º 5
0
 def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:
     from kitty.fast_data_types import get_options
     opts = get_options()
     ans = {k: getattr(opts, k) for k in opts if isinstance(getattr(opts, k), Color)}
     if not payload_get('configured'):
         windows = self.windows_for_match_payload(boss, window, payload_get)
         if windows and windows[0]:
             for k, v in windows[0].current_colors.items():
                 if v is None:
                     ans.pop(k, None)
                 else:
                     ans[k] = color_from_int(v)
     all_keys = natsort_ints(ans)
     maxlen = max(map(len, all_keys))
     return '\n'.join(('{:%ds} {}' % maxlen).format(key, color_as_sharp(ans[key])) for key in all_keys)
Exemplo n.º 6
0
 def response_from_kitty(self, boss: Boss, window: Optional[Window],
                         payload_get: PayloadGetType) -> ResponseType:
     ans = {
         k: getattr(boss.opts, k)
         for k in boss.opts if isinstance(getattr(boss.opts, k), Color)
     }
     if not payload_get('configured'):
         windows = self.windows_for_match_payload(boss, window, payload_get)
         ans.update({
             k: color_from_int(v)
             for k, v in windows[0].current_colors.items()
         })
     all_keys = natsort_ints(ans)
     maxlen = max(map(len, all_keys))
     return '\n'.join(
         ('{:%ds} {}' % maxlen).format(key, color_as_sharp(ans[key]))
         for key in all_keys)
Exemplo n.º 7
0
 def set_colors_to_current_theme(self) -> bool:
     if not self.themes_list and self.colors_set_once:
         return False
     self.colors_set_once = True
     if self.themes_list:
         o = self.themes_list.current_theme.kitty_opts
     else:
         o = create_default_opts()
     self.cmd.set_default_colors(
         fg=o.foreground, bg=o.background, cursor=o.cursor, select_bg=o.selection_background, select_fg=o.selection_foreground
     )
     self.current_opts = o
     cmds = []
     for i in range(256):
         col = color_as_sharp(color_from_int(o.color_table[i]))
         cmds.append(f'{i};{col}')
     self.print(end='\033]4;' + ';'.join(cmds) + '\033\\')
     return True