File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 11import subprocess
2- from ..utils import ThreadedSegment
2+ from ..utils import ThreadedSegment , find_upwards
33
44
55class Segment (ThreadedSegment ):
@@ -12,7 +12,14 @@ def run(self):
1212
1313 def add_to_powerline (self ):
1414 self .join ()
15+
16+ require_package = self .powerline .segment_conf ("node_version" , "require_package" , False )
17+ chars = int (self .powerline .segment_conf ("node_version" , "chars" , 10 ))
18+ has_node = find_upwards ("package.json" ) != None
19+
20+ if require_package and not has_node :
21+ return
1522 if not self .version :
1623 return
1724 # FIXME no hard-coded colors
18- self .powerline .append ("node " + self .version , 15 , 18 )
25+ self .powerline .append (" node " + self .version [: chars ] , 15 , 18 )
Original file line number Diff line number Diff line change 11import sys
22import os
33import threading
4+ from pathlib import Path
45
56py3 = sys .version_info [0 ] == 3
67
@@ -150,3 +151,9 @@ def get_git_subprocess_env():
150151 # Otherwise we may be unable to parse the output.
151152 return get_subprocess_env (LANG = "C" )
152153
154+
155+ def find_upwards (filename : str , cwd : Path = Path .cwd ()) -> Path | None :
156+ if cwd == Path (cwd .root ) or cwd == cwd .parent :
157+ return None
158+ fullpath = cwd / filename
159+ return fullpath if fullpath .exists () else find_upwards (filename , cwd .parent )
You can’t perform that action at this time.
0 commit comments