-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwc_linemode.py
36 lines (27 loc) · 1.02 KB
/
wc_linemode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import ranger.api
from ranger.core.linemode import LinemodeBase
from .wc_helper import WCHelper
@ranger.api.register_linemode
class WCLinemode(LinemodeBase):
name = "wc"
uses_metadata = False
def __init__(self):
"Initialize the ranger wordcount linemode plugin"
self.wc_helper = WCHelper()
def call_wc(self, filename: str) -> str:
"Call wc and return the results"
return self.wc_helper.call_wc(filename)
def get_wc_string(self, res: str) -> str:
"Convert the wc result to a string"
return self.wc_helper.get_wc_string(res)
def get_wc(self, res: str) -> int:
"Parse the word count from the wc process call"
return self.wc_helper.get_wc(res)
def filetitle(self, fobj, metadata) -> str:
return fobj.relative_path
def infostring(self, fobj, metadata) -> str:
"""
Add the number of words in the file to the linemode
Or return the empty string
"""
return self.wc_helper.infostring(fobj, metadata)