Also output layout state in kitty @ ls

This commit is contained in:
Kovid Goyal
2021-04-17 12:11:56 +05:30
parent cf0b2389a3
commit 518057489c
6 changed files with 45 additions and 6 deletions

View File

@@ -5,8 +5,8 @@
from functools import partial from functools import partial
from itertools import repeat from itertools import repeat
from typing import ( from typing import (
Dict, Generator, Iterable, Iterator, List, NamedTuple, Optional, Sequence, Any, Dict, Generator, Iterable, Iterator, List, NamedTuple, Optional,
Tuple Sequence, Tuple
) )
from kitty.borders import BorderColor from kitty.borders import BorderColor
@@ -380,3 +380,6 @@ class Layout:
def layout_action(self, action_name: str, args: Sequence[str], all_windows: WindowList) -> Optional[bool]: def layout_action(self, action_name: str, args: Sequence[str], all_windows: WindowList) -> Optional[bool]:
pass pass
def layout_state(self) -> Dict[str, Any]:
return {}

View File

@@ -6,7 +6,7 @@ from functools import lru_cache
from itertools import repeat from itertools import repeat
from math import ceil, floor from math import ceil, floor
from typing import ( from typing import (
Callable, Dict, Generator, List, Optional, Sequence, Set, Tuple Any, Callable, Dict, Generator, List, Optional, Sequence, Set, Tuple
) )
from kitty.borders import BorderColor from kitty.borders import BorderColor
@@ -294,3 +294,9 @@ class Grid(Layout):
'left': side(row, col, -1) if col else [], 'left': side(row, col, -1) if col else [],
'right': side(row, col, 1) if col < ncols - 1 else [], 'right': side(row, col, 1) if col < ncols - 1 else [],
} }
def layout_state(self) -> Dict[str, Any]:
return {
'biased_cols': self.biased_cols,
'biased_rows': self.biased_rows
}

View File

@@ -3,7 +3,7 @@
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
from typing import ( from typing import (
Collection, Dict, Generator, List, NamedTuple, Optional, Sequence, Tuple, Any, Collection, Dict, Generator, List, NamedTuple, Optional, Sequence, Tuple,
Union Union
) )
@@ -546,3 +546,21 @@ class Splits(Layout):
if swap: if swap:
pair.one, pair.two = pair.two, pair.one pair.one, pair.two = pair.two, pair.one
return True return True
def layout_state(self) -> Dict[str, Any]:
def add_pair(p: Pair) -> Dict[str, Any]:
ans: Dict[str, Any] = {}
ans['horizontal'] = p.horizontal
ans['bias'] = p.bias
if isinstance(p.one, Pair):
ans['one'] = add_pair(p.one)
elif p.one is not None:
ans['one'] = p.one
if isinstance(p.two, Pair):
ans['two'] = add_pair(p.two)
elif p.one is not None:
ans['two'] = p.two
return ans
return {'pairs': add_pair(self.pairs_root)}

View File

@@ -3,7 +3,7 @@
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
from itertools import islice, repeat from itertools import islice, repeat
from typing import Dict, Generator, List, Optional, Sequence, Tuple from typing import Any, Dict, Generator, List, Optional, Sequence, Tuple
from kitty.borders import BorderColor from kitty.borders import BorderColor
from kitty.conf.utils import to_bool from kitty.conf.utils import to_bool
@@ -278,6 +278,13 @@ class Tall(Layout):
) )
yield from perp_borders[1:-1] yield from perp_borders[1:-1]
def layout_state(self) -> Dict[str, Any]:
return {
'num_full_size_windows': self.num_full_size_windows,
'main_bias': self.main_bias,
'biased_map': self.biased_map
}
class Fat(Tall): class Fat(Tall):

View File

@@ -2,7 +2,7 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
from typing import Dict, Generator, Iterable, List, Tuple from typing import Any, Dict, Generator, Iterable, List, Tuple
from kitty.borders import BorderColor from kitty.borders import BorderColor
from kitty.types import Edges from kitty.types import Edges
@@ -130,6 +130,9 @@ class Vertical(Layout):
return {'left': before, 'right': after, 'top': [], 'bottom': []} return {'left': before, 'right': after, 'top': [], 'bottom': []}
return {'top': before, 'bottom': after, 'left': [], 'right': []} return {'top': before, 'bottom': after, 'left': [], 'right': []}
def layout_state(self) -> Dict[str, Any]:
return {'biased_map': self.biased_map}
class Horizontal(Vertical): class Horizontal(Vertical):

View File

@@ -38,6 +38,7 @@ class TabDict(TypedDict):
is_focused: bool is_focused: bool
title: str title: str
layout: str layout: str
layout_state: Dict[str, Any]
windows: List[WindowDict] windows: List[WindowDict]
active_window_history: List[int] active_window_history: List[int]
@@ -671,6 +672,7 @@ class TabManager: # {{{
'is_focused': tab is active_tab, 'is_focused': tab is active_tab,
'title': tab.name or tab.title, 'title': tab.name or tab.title,
'layout': str(tab.current_layout.name), 'layout': str(tab.current_layout.name),
'layout_state': tab.current_layout.layout_state(),
'windows': list(tab.list_windows(active_window, self_window)), 'windows': list(tab.list_windows(active_window, self_window)),
'active_window_history': list(tab.windows.active_window_history), 'active_window_history': list(tab.windows.active_window_history),
} }