@@ -15,19 +15,19 @@ $PL_DEFAULT_RPROMPT = 'history>time'
1515$PL_DEFAULT_TOOLBAR = 'who>cwd>branch>virtualenv>full_proc'
1616$PL_DEFAULT_EXTRA_SEC = {'user' : lambda : [' {user} ' , 'WHITE' , '#555' ]}
1717$PL_DEFAULT_COLORS = {
18- "time" : ("BLACK" , "#00adee" ),
1918 "who" : ("BLACK" , "#a6e22e" ),
20- "short_cwd" : ("WHITE" , "#444" ),
19+ "venv" : ("BLACK" , "INTENSE_GREEN" ),
20+ "branch" : ("#333" ),
2121 "cwd" : ("WHITE" , "#444" ),
2222 "git_root" : ("BLACK" , "#00adee" ),
2323 "git_sub_dir" : ("WHITE" , "#00adee" ),
24- "history " : ("WHITE" , "#333333 " ),
25- "venv " : ("BLACK " , "INTENSE_GREEN " ),
24+ "short_cwd " : ("WHITE" , "#444 " ),
25+ "full_proc " : ("WHITE " , "RED" , "#444 " ),
2626 "timing" : ("WHITE" , "#444" ),
27+ "time" : ("BLACK" , "#00adee" ),
28+ "history" : ("WHITE" , "#333333" ),
2729 "rtns" : ("WHITE" , "RED" ),
2830 "full_rtns" : ("WHITE" , "RED" , "#444" ),
29- "full_proc" : ("WHITE" , "RED" , "#444" ),
30- "branch" : ("#333" )
3131 }
3232
3333if ptk_shell_type () == 'prompt_toolkit2' :
@@ -59,17 +59,21 @@ def register_sec(f):
5959
6060
6161@register_sec
62- def history ():
62+ def history (sample = False ):
63+ if sample :
64+ return Section (' 100 ' , * $PL_COLORS ["history" ])
6365 return Section (' %d ' % len (__xonsh__ .history ), * $PL_COLORS ["history" ])
6466
6567
6668@register_sec
67- def time ():
69+ def time (sample = False ):
6870 return Section (strftime (' %H:%M ' ), * $PL_COLORS ["time" ])
6971
7072
7173@register_sec
72- def short_cwd ():
74+ def short_cwd (sample = False ):
75+ if sample :
76+ return Section (' ~/e/h/p/fuga ' , * $PL_COLORS ["short_cwd" ])
7377 return Section (' {short_cwd} ' , * $PL_COLORS ["short_cwd" ])
7478
7579
@@ -80,11 +84,15 @@ def compress_home(path):
8084
8185
8286@register_sec
83- def cwd ():
87+ def cwd (sample = False ):
8488 ps = compress_home ($PWD ).strip (os .sep ).split (os .sep )
89+ if sample :
90+ ps = ['~' ,'example' ,'hoge' ,'piyo' ,'fuga' ]
8591
8692 if $PROMPT_FIELDS ['curr_branch' ]():
8793 prefix = $(git rev - parse - - show - prefix ).strip ()
94+ if sample :
95+ prefix = ['hoge' , 'piyo' , 'fuga' ]
8896 ni = - 1
8997 if prefix != '' :
9098 subs = prefix .rstrip (os .sep ).split (os .sep )
@@ -107,40 +115,56 @@ def cwd():
107115
108116
109117@register_sec
110- def branch ():
118+ def branch (sample = False ):
119+ if sample :
120+ return [
121+ Section (' hoge ' , $PL_COLORS ['branch' ], 'YELLOW' ),
122+ Section (' piyo ' , $PL_COLORS ['branch' ], 'GREEN' ),
123+ Section (' fuga ' , $PL_COLORS ['branch' ], 'RED' )]
111124 if $PROMPT_FIELDS ['curr_branch' ]():
112125 return Section (' {curr_branch} ' , $PL_COLORS ['branch' ], $PROMPT_FIELDS ['branch_bg_color' ]()[1 + len ('background_' ):- 1 ])
113126
114127
115128@register_sec
116- def virtualenv ():
129+ def virtualenv (sample = False ):
130+ if sample :
131+ return Section (' 🐍 example env' , * $PL_COLORS ["venv" ])
117132 if $PROMPT_FIELDS ['env_name' ]():
118133 return Section (' 🐍 {env_name} ' , * $PL_COLORS ["venv" ])
119134
120135
121136@register_sec
122- def rtns ():
137+ def rtns (sample = False ):
138+ if sample :
139+ return Section (' ! ' , * $PL_COLORS ['rtns' ])
123140 if __xonsh__ .history .rtns and __xonsh__ .history .rtns [- 1 ] != 0 :
124141 return Section (' ! ' , * $PL_COLORS ['rtns' ])
125142
126-
127143@register_sec
128- def full_rtns ():
144+ def full_rtns (sample = False ):
145+ if sample :
146+ return [Section (' hoge ' , $PL_COLORS ['full_rtns' ][0 ], $PL_COLORS ['full_rtns' ][1 ]),
147+ Section (' piyo ' , $PL_COLORS ['full_rtns' ][0 ], $PL_COLORS ['full_rtns' ][2 ])]
129148 if __xonsh__ .history .rtns :
130149 rtn = __xonsh__ .history .rtns [- 1 ]
131150 color = $PL_COLORS ['full_rtns' ][1 ] if rtn != 0 else $PL_COLORS ['full_rtns' ][2 ]
132151 return Section (' ' + str (rtn ) + ' ' , $PL_COLORS ['full_rtns' ][0 ], color )
133152
134153
135154@register_sec
136- def timing ():
155+ def timing (sample = False ):
156+ if sample :
157+ return Section (' 0.01s ' , * $PL_COLORS ['timing' ])
137158 if __xonsh__ .history .tss :
138159 tss = __xonsh__ .history .tss [- 1 ]
139160 return Section (' %.2fs ' % (tss [1 ] - tss [0 ]), * $PL_COLORS ['timing' ])
140161
141162
142163@register_sec
143- def full_proc ():
164+ def full_proc (sample = False ):
165+ if sample :
166+ return [Section (' rtn: 1 ts: 0.01s ' , $PL_COLORS ['full_proc' ][0 ], $PL_COLORS ['full_proc' ][1 ]),
167+ Section (' rtn: 2 ts: 0.02s ' , $PL_COLORS ['full_proc' ][0 ], $PL_COLORS ['full_proc' ][2 ])]
144168 if __xonsh__ .history .buffer :
145169 lst = __xonsh__ .history .buffer [- 1 ]
146170 color = $PL_COLORS ['full_proc' ][1 ] if lst ['rtn' ] != 0 else $PL_COLORS ['full_proc' ][2 ]
@@ -149,11 +173,11 @@ def full_proc():
149173
150174
151175@register_sec
152- def who ():
176+ def who (sample = False ):
153177 return Section (' {user}@{hostname} ' , * $PL_COLORS ["who" ])
154178
155179
156- def prompt_builder (var , right = False ):
180+ def prompt_builder (var , right = False , sample = False ):
157181 if var == '!' :
158182 return ''
159183
@@ -173,9 +197,12 @@ def prompt_builder(var, right=False):
173197 if isinstance (s , Section ):
174198 sections .append (s )
175199 else :
176- r = s ()
200+ r = s (sample )
177201 if r is not None :
178- sections .append (r )
202+ if type (r ) == list :
203+ sections += r
204+ else :
205+ sections .append (r )
179206
180207 size = len (sections )
181208 for i , sec in enumerate (sections ):
@@ -211,21 +238,32 @@ def pl_set_mode(args):
211238 for mode , seps in modes .items ():
212239 print ('%s: %s' % (mode , ', ' .join (seps )))
213240 return
241+ $PL_SEP_MODE = args [0 ]
214242 seps = modes [args [0 ]]
215243 $PL_SEP , $PL_SEP_THIN , $PL_RSEP , _ = seps
244+ if 'PL_ORG_SEP' in ${...}:
245+ $PL_SEP = $PL_ORG_SEP
246+ if 'PL_ORG_SEP_THIN' in ${...}:
247+ $PL_SEP_THIN = $PL_ORG_SEP_THIN
248+ if 'PL_ORG_RSEP' in ${...}:
249+ $PL_RSEP = $PL_ORG_RSEP
216250
217251
218252@alias
219253def pl_available_sections ():
220254 for name in available_sections .keys ():
221- r = prompt_builder (name )()
255+ if name in ['branch' , 'virtualenv' , 'rtns' , 'full_rtns' , 'timing' , 'full_proc' , 'cwd' , 'short_cwd' ]:
256+ r = prompt_builder (name , sample = True )()
257+ else :
258+ r = prompt_builder (name )()
222259 f = __xonsh__ .shell .prompt_formatter (r )
223260 __xonsh__ .shell .print_color ('%s: %s' % (name , f ))
224261
225262
226263@alias
227264def pl_build_prompt ():
228- pl_set_mode (['powerline' ])
265+ $PL_SEP_MODE = 'powerline' if 'PL_SEP_MODE' not in ${...} else $PL_SEP_MODE
266+ pl_set_mode ([$PL_SEP_MODE ])
229267 for var in 'PROMPT RPROMPT TOOLBAR' .split ():
230268 varname = 'PL_' + var
231269 defname = 'PL_DEFAULT_' + var
0 commit comments