ADD: Search command

main
Kamal Curi 4 years ago
parent 617c14b9dd
commit d16f40cd46

@ -23,7 +23,7 @@ import os
import pyperclip as pc import pyperclip as pc
import random import random
version = sys.argv[1] version = "v120d"
## Initialization of bottomline dependencies ## Initialization of bottomline dependencies
@ -37,7 +37,7 @@ fields = ["service", "user", "pswd"]
# Password file # Password file
HOMEDIR = os.environ['HOME'] HOMEDIR = os.environ['HOME']
PASFILE=HOMEDIR+"/.pasfile.csv" PASFILE="pasfile.csv"
def reloadFiles(): def reloadFiles():
files.clear() files.clear()
@ -98,12 +98,19 @@ def displayItems():
cleanWins() cleanWins()
global NROWS global NROWS
global ITEM_CURSOR global ITEM_CURSOR
global SQUERY
# Creates a name list # Creates a name list
global displayList global displayList
displayList = [] displayList = []
# Appends the names in the CSV to display on the main window # Appends the names in the CSV to display on the main window
if SQUERY == '':
for ps_name in files: for ps_name in files:
displayList.append(ps_name['service'][:15]) displayList.append(ps_name['service'][:15])
else:
for ps_name in files:
sname = ps_name['service']
if ps_name['service'].find(SQUERY) != -1:
displayList.append(ps_name['service'][:15])
# Reset global necessities # Reset global necessities
LINE = 0 LINE = 0
@ -113,8 +120,8 @@ def displayItems():
global highOpt global highOpt
highOpt = () highOpt = ()
# Defines what to display # Defines what to display
startDisplay = (CURR_PAGE-1)*MAX_ITEMS startDisplay = (CURR_PAGE-1)*len(displayList)
stopDisplay = CURR_PAGE*MAX_ITEMS stopDisplay = CURR_PAGE*len(displayList)
for item in displayList[startDisplay:stopDisplay]: for item in displayList[startDisplay:stopDisplay]:
# If the item is the one with the cursor, highlight it # If the item is the one with the cursor, highlight it
@ -130,7 +137,7 @@ def displayItems():
LINE = 0 LINE = 0
COLUMN+=16 COLUMN+=16
NROWS+=1 NROWS+=1
STATUS_MESSAGE = "(n)ew,(d|el),(c)opy,(m)odify,(h)elp,(q)uit" STATUS_MESSAGE = "(n)ew,(d|el),(s)earch,(c)opy,(m)odify,(h)elp,(q)uit"
displayStatus(STATUS_MESSAGE) displayStatus(STATUS_MESSAGE)
mainwin.refresh() mainwin.refresh()
@ -192,6 +199,8 @@ def globals():
PUSER = "" PUSER = ""
global PPSWD global PPSWD
PPSWD = "" PPSWD = ""
global SQUERY
SQUERY = ""
# This makes sure that if anyone resizes the terminal window, it won't be smaller than the maximum size # This makes sure that if anyone resizes the terminal window, it won't be smaller than the maximum size
def termGlobals(): def termGlobals():
@ -253,6 +262,8 @@ def command():
examine() examine()
elif c == ord('c') or c == curses.KEY_F3: elif c == ord('c') or c == curses.KEY_F3:
copy() copy()
elif c == ord('s') or c == curses.KEY_F6:
searchWin()
elif c == ord('n') or c == curses.KEY_F4: elif c == ord('n') or c == curses.KEY_F4:
newFile() newFile()
elif c == ord('m') or c == curses.KEY_F5: elif c == ord('m') or c == curses.KEY_F5:
@ -495,6 +506,25 @@ def copy():
displayStatus(STATUS_MESSAGE) displayStatus(STATUS_MESSAGE)
mainwin.getch() mainwin.getch()
def searchWin():
global STATUS_MESSAGE
global TERM_LINES
global TERM_COLS
global SQUERY
searchWin = curses.newwin(3, 49, int(TERM_LINES/2), int(TERM_COLS/2))
searchWin.border()
searchWin.addstr(0, 1, "Search service")
winPosY = searchWin.getbegyx()[0]
winPosX = searchWin.getbegyx()[1]
swin = curses.newwin(1, 45, winPosY + 1, winPosX + 1)
sbox = Textbox(swin)
STATUS_MESSAGE = "Type in service name"
displayStatus(STATUS_MESSAGE)
searchWin.refresh()
sbox.edit()
SQUERY = sbox.gather()
l = len(SQUERY)
SQUERY = SQUERY[:l-1]
# Cleans the windows # Cleans the windows

@ -6,7 +6,7 @@
version="1.04" version="1.04"
echo "Steelbox V$version, Copyright (C) 2022 Kamal Curi" echo "Steelbox V$version, Copyright (C) 2022 Kamal Curi"
echo "Read the manual in doc/ for the GPL2 License's details." echo "Steelbox comes with ABSOLUTELY NO WARRANTY; for details, read the manual in doc/"
if [ -f $HOME/.pasfile.csv.gpg ] if [ -f $HOME/.pasfile.csv.gpg ]

Loading…
Cancel
Save