or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

console.mdcontainers.mdindex.mdinteractive.mdlayout.mdmarkdown.mdprogress.mdsyntax.mdtables.mdtext-styling.mdutilities.md

layout.mddocs/

0

# Layout System

1

2

Advanced layout system for complex terminal UIs with flexible positioning and sizing. Rich provides powerful layout management for creating sophisticated terminal applications with responsive design.

3

4

## Capabilities

5

6

### Layout Class

7

8

Main layout management system with flexible splitting and positioning.

9

10

```python { .api }

11

class Layout:

12

"""

13

Layout management for terminal UIs.

14

15

Args:

16

renderable: Initial content to display

17

name: Layout identifier

18

size: Fixed size or None for flexible

19

minimum_size: Minimum size constraint

20

ratio: Size ratio for flexible layouts

21

visible: Layout visibility

22

"""

23

def __init__(

24

self,

25

renderable: Optional[RenderableType] = None,

26

*,

27

name: str = "root",

28

size: Optional[int] = None,

29

minimum_size: int = 1,

30

ratio: int = 1,

31

visible: bool = True,

32

): ...

33

34

def split(

35

self,

36

*layouts: Union["Layout", RenderableType],

37

splitter: Splitter = "column",

38

) -> None:

39

"""

40

Split layout into multiple sections.

41

42

Args:

43

*layouts: Child layouts or renderables

44

splitter: Split direction ("column" or "row")

45

"""

46

47

def split_column(self, *layouts: Union["Layout", RenderableType]) -> None:

48

"""Split layout vertically."""

49

50

def split_row(self, *layouts: Union["Layout", RenderableType]) -> None:

51

"""Split layout horizontally."""

52

53

def add_split(self, *layouts: Union["Layout", RenderableType]) -> None:

54

"""Add layouts to existing split."""

55

56

def unsplit(self) -> "Layout":

57

"""Remove split and return to single layout."""

58

59

def update(self, renderable: RenderableType) -> None:

60

"""Update layout content."""

61

62

def refresh_screen(self, console: Console, size: ConsoleDimensions) -> None:

63

"""Refresh layout display."""

64

65

class Splitter(ABC):

66

"""Abstract base for layout splitters."""

67

68

@abstractmethod

69

def divide(

70

self,

71

children: Sequence[Layout],

72

size: int

73

) -> List[int]: ...

74

75

class RowSplitter(Splitter):

76

"""Horizontal layout splitter."""

77

78

class ColumnSplitter(Splitter):

79

"""Vertical layout splitter."""

80

```

81

82

**Usage Examples:**

83

84

```python

85

from rich.console import Console

86

from rich.layout import Layout

87

from rich.panel import Panel

88

89

console = Console()

90

91

# Basic layout

92

layout = Layout()

93

layout.split_column(

94

Layout(Panel("Header", style="blue")),

95

Layout(Panel("Content", style="green")),

96

Layout(Panel("Footer", style="red"))

97

)

98

console.print(layout)

99

100

# Complex layout with ratios

101

layout = Layout()

102

layout.split_column(

103

Layout(Panel("Header"), size=3),

104

Layout(name="main"),

105

Layout(Panel("Footer"), size=3)

106

)

107

layout["main"].split_row(

108

Layout(Panel("Left"), name="left"),

109

Layout(Panel("Right"), name="right")

110

)

111

console.print(layout)

112

```