mirror of https://github.com/aristocratos/bpytop
Merge branch 'proc-filter'
commit
86f1a1f18b
27
bpytop.py
27
bpytop.py
|
@ -2566,7 +2566,7 @@ class ProcBox(Box):
|
||||||
if not "delete" in Key.mouse: Key.mouse["delete"] = [[x+12 + len(proc.search_filter[-10:]) + i, y-1] for i in range(3)]
|
if not "delete" in Key.mouse: Key.mouse["delete"] = [[x+12 + len(proc.search_filter[-10:]) + i, y-1] for i in range(3)]
|
||||||
elif "delete" in Key.mouse:
|
elif "delete" in Key.mouse:
|
||||||
del Key.mouse["delete"]
|
del Key.mouse["delete"]
|
||||||
out_misc += (f'{Mv.to(y-1, x + 8)}{THEME.proc_box(Symbol.title_left)}{Fx.b if cls.filtering or proc.search_filter else ""}{THEME.hi_fg("f")}{THEME.title}' +
|
out_misc += (f'{Mv.to(y-1, x + 8)}{THEME.proc_box(Symbol.title_left)}{Fx.b if cls.filtering or proc.search_filter else ""}{THEME.hi_fg("F" if cls.filtering and proc.case_sensitive else "f")}{THEME.title}' +
|
||||||
("ilter" if not proc.search_filter and not cls.filtering else f' {proc.search_filter[-(10 if w < 83 else w - 74):]}{(Fx.bl + "█" + Fx.ubl) if cls.filtering else THEME.hi_fg(" del")}') +
|
("ilter" if not proc.search_filter and not cls.filtering else f' {proc.search_filter[-(10 if w < 83 else w - 74):]}{(Fx.bl + "█" + Fx.ubl) if cls.filtering else THEME.hi_fg(" del")}') +
|
||||||
f'{THEME.proc_box(Symbol.title_right)}')
|
f'{THEME.proc_box(Symbol.title_right)}')
|
||||||
|
|
||||||
|
@ -3523,6 +3523,7 @@ class ProcCollector(Collector):
|
||||||
'''Collects process stats'''
|
'''Collects process stats'''
|
||||||
buffer: str = ProcBox.buffer
|
buffer: str = ProcBox.buffer
|
||||||
search_filter: str = ""
|
search_filter: str = ""
|
||||||
|
case_sensitive: bool = False
|
||||||
processes: Dict = {}
|
processes: Dict = {}
|
||||||
num_procs: int = 0
|
num_procs: int = 0
|
||||||
det_cpu: float = 0.0
|
det_cpu: float = 0.0
|
||||||
|
@ -3554,7 +3555,12 @@ class ProcCollector(Collector):
|
||||||
sorting: str = CONFIG.proc_sorting
|
sorting: str = CONFIG.proc_sorting
|
||||||
reverse: bool = not CONFIG.proc_reversed
|
reverse: bool = not CONFIG.proc_reversed
|
||||||
proc_per_cpu: bool = CONFIG.proc_per_core
|
proc_per_cpu: bool = CONFIG.proc_per_core
|
||||||
search: str = cls.search_filter
|
search: List[str] = []
|
||||||
|
if cls.search_filter:
|
||||||
|
if cls.case_sensitive:
|
||||||
|
search = [i.strip() for i in cls.search_filter.split(",")]
|
||||||
|
else:
|
||||||
|
search = [i.strip() for i in cls.search_filter.lower().split(",")]
|
||||||
err: float = 0.0
|
err: float = 0.0
|
||||||
n: int = 0
|
n: int = 0
|
||||||
|
|
||||||
|
@ -3581,8 +3587,10 @@ class ProcCollector(Collector):
|
||||||
if cls.detailed and p.info["pid"] == cls.detailed_pid:
|
if cls.detailed and p.info["pid"] == cls.detailed_pid:
|
||||||
cls.det_cpu = p.info["cpu_percent"]
|
cls.det_cpu = p.info["cpu_percent"]
|
||||||
for value in [ p.info["name"], " ".join(p.info["cmdline"]), str(p.info["pid"]), p.info["username"] ]:
|
for value in [ p.info["name"], " ".join(p.info["cmdline"]), str(p.info["pid"]), p.info["username"] ]:
|
||||||
for s in search.split(","):
|
if not cls.case_sensitive:
|
||||||
if s.strip() in value:
|
value = value.lower()
|
||||||
|
for s in search:
|
||||||
|
if s in value:
|
||||||
break
|
break
|
||||||
else: continue
|
else: continue
|
||||||
break
|
break
|
||||||
|
@ -3694,7 +3702,7 @@ class ProcCollector(Collector):
|
||||||
if len(cls.details_mem) > ProcBox.width: del cls.details_mem[0]
|
if len(cls.details_mem) > ProcBox.width: del cls.details_mem[0]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _tree(cls, sort_cmd, reverse: bool, proc_per_cpu: bool, search: str):
|
def _tree(cls, sort_cmd, reverse: bool, proc_per_cpu: bool, search: List[str]):
|
||||||
'''List all processess in a tree view with pid, name, threads, username, memory percent and cpu percent'''
|
'''List all processess in a tree view with pid, name, threads, username, memory percent and cpu percent'''
|
||||||
out: Dict = {}
|
out: Dict = {}
|
||||||
err: float = 0.0
|
err: float = 0.0
|
||||||
|
@ -3737,8 +3745,10 @@ class ProcCollector(Collector):
|
||||||
if "username" in getinfo and isinstance(getinfo["username"], float): getinfo["username"] = ""
|
if "username" in getinfo and isinstance(getinfo["username"], float): getinfo["username"] = ""
|
||||||
if "cmdline" in getinfo and isinstance(getinfo["cmdline"], float): getinfo["cmdline"] = ""
|
if "cmdline" in getinfo and isinstance(getinfo["cmdline"], float): getinfo["cmdline"] = ""
|
||||||
for value in [ name, str(pid), getinfo.get("username", ""), " ".join(getinfo.get("cmdline", "")) ]:
|
for value in [ name, str(pid), getinfo.get("username", ""), " ".join(getinfo.get("cmdline", "")) ]:
|
||||||
for s in search.split(","):
|
if not cls.case_sensitive:
|
||||||
if s.strip() in value:
|
value = value.lower()
|
||||||
|
for s in search:
|
||||||
|
if s in value:
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
else: continue
|
else: continue
|
||||||
|
@ -5178,8 +5188,9 @@ def process_keys():
|
||||||
elif key == "c":
|
elif key == "c":
|
||||||
CONFIG.proc_per_core = not CONFIG.proc_per_core
|
CONFIG.proc_per_core = not CONFIG.proc_per_core
|
||||||
Collector.collect(ProcCollector, interrupt=True, redraw=True)
|
Collector.collect(ProcCollector, interrupt=True, redraw=True)
|
||||||
elif key == "f":
|
elif key in ["f", "F"]:
|
||||||
ProcBox.filtering = True
|
ProcBox.filtering = True
|
||||||
|
ProcCollector.case_sensitive = key == "F"
|
||||||
if not ProcCollector.search_filter: ProcBox.start = 0
|
if not ProcCollector.search_filter: ProcBox.start = 0
|
||||||
Collector.collect(ProcCollector, redraw=True, only_draw=True)
|
Collector.collect(ProcCollector, redraw=True, only_draw=True)
|
||||||
elif key in ["T", "K", "I"] and (ProcBox.selected > 0 or ProcCollector.detailed):
|
elif key in ["T", "K", "I"] and (ProcBox.selected > 0 or ProcCollector.detailed):
|
||||||
|
|
Loading…
Reference in New Issue