Skip to content

Commit

Permalink
Merge pull request #16 from vaaaaanquish/multiline
Browse files Browse the repository at this point in the history
multiline
  • Loading branch information
vaaaaanquish committed Dec 27, 2020
2 parents 200f8c5 + 4346793 commit 00c55da
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 38 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ xontrib load powerline2

# Configuration

There are two variables that can be set, ``$PROMPT`` for main prompt, ``$PL_PROMPT`` for the right prompt and ``$PL_TOOLBAR`` for the bottom toolbar.
There are two variables that can be set, ``$PL_PROMPT`` for main prompt, ``$PL_PROMPT`` for the right prompt and ``$PL_TOOLBAR`` for the bottom toolbar.
They contain a list of sections that can be used separated by ``>``. The value ``!`` means not to use that prompt.

Examples:
Expand Down Expand Up @@ -99,6 +99,15 @@ We can change section color by `$PL_COLORS`.
|full_rtns| ("WHITE", "RED", "#444") |There are two types of background depending on the situation|


## Multi line prompt

We can use multi line prompt by `\n`.
```
$PL_PROMPT='\nuser>mode>\ncwd'
```

<img src="https://github.com/vaaaaanquish/xontrib-powerline2/raw/master/img/example_multiline.png" alt="example" title="multiline">

## Separate mode

We can change the way of separation mode by `$PL_SEP_MODE`.
Expand Down
Binary file added img/example_multiline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='xontrib-powerline2',
version='1.2.2',
version='1.3.0',
description='Powerline for Xonsh shell',
long_description=open('README.md').read(),
long_description_content_type="text/markdown",
Expand Down
78 changes: 42 additions & 36 deletions xontrib/powerline2.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -191,45 +191,51 @@ def prompt_builder(var, right=False, sample=False):
if var == '!':
return ''

pre_sections = []
for e in var.split('>'):
if e not in available_sections:
print('section %s not found, skipping it' % e)
continue
pre_sections.append(available_sections[e])
multiline = []
for line in var.split('\n'):
pre_sections = []
for e in line.split('>'):
if e not in available_sections:
print('section %s not found, skipping it' % e)
continue
pre_sections.append(available_sections[e])
multiline.append(pre_sections)

def prompt():
p = []
sections = []
for s in pre_sections:
if type(s()) == list:
s = Section(*s())
if isinstance(s, Section):
sections.append(s)
else:
r = s(sample)
if r is not None:
if type(r) == list:
sections += r
else:
sections.append(r)

size = len(sections)
for i, sec in enumerate(sections):
last = (i == size-1)
first = (i == 0)

if right:
p.append('{%s}%s{BACKGROUND_%s}{%s}%s' % (sec.bg, $PL_RSEP, sec.bg, sec.fg, sec.line))
else:
if first:
p.append('{BACKGROUND_%s}' % sec.bg)
p.append('{%s}%s' % (sec.fg, sec.line))
if last:
p.append('{%s}{%s}%s{%s} ' % (COLOR_TOKEN, sec.bg, $PL_SEP, COLOR_TOKEN))
multiline_prompt = []
for pre_sections in multiline:
p = []
sections = []
for s in pre_sections:
if type(s()) == list:
s = Section(*s())
if isinstance(s, Section):
sections.append(s)
else:
r = s(sample)
if r is not None:
if type(r) == list:
sections += r
else:
sections.append(r)

size = len(sections)
for i, sec in enumerate(sections):
last = (i == size-1)
first = (i == 0)

if right:
p.append('{%s}%s{BACKGROUND_%s}{%s}%s' % (sec.bg, $PL_RSEP, sec.bg, sec.fg, sec.line))
else:
p.append('{BACKGROUND_%s}{%s}%s' % (sections[i+1].bg, sec.bg, $PL_SEP))
return ''.join(p)
if first:
p.append('{BACKGROUND_%s}' % sec.bg)
p.append('{%s}%s' % (sec.fg, sec.line))
if last:
p.append('{%s}{%s}%s{%s} ' % (COLOR_TOKEN, sec.bg, $PL_SEP, COLOR_TOKEN))
else:
p.append('{BACKGROUND_%s}{%s}%s' % (sections[i+1].bg, sec.bg, $PL_SEP))
multiline_prompt.append(''.join(p))
return '\n'.join(multiline_prompt)
return prompt


Expand Down

0 comments on commit 00c55da

Please sign in to comment.