From e9e2d6900d2213708aedac27b188e5beead1cb62 Mon Sep 17 00:00:00 2001 From: Saul Pwanson Date: Fri, 27 Oct 2023 17:18:59 -0700 Subject: [PATCH] [input] allow percent of starting value #2082 --- visidata/_input.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/visidata/_input.py b/visidata/_input.py index 9c85ee917..8c4e2dc68 100644 --- a/visidata/_input.py +++ b/visidata/_input.py @@ -314,7 +314,7 @@ def find_nonword(s, a, b, incr): first_action = False complete_state.reset() - return type(value)(v) + return v @VisiData.api @@ -338,8 +338,15 @@ def editText(vd, y, x, w, record=True, display=True, **kwargs): if record and vd.cmdlog: vd.setLastArgs(v) - return v + if 'value' in kwargs: + starting_value = kwargs['value'] + if isinstance(starting_value, (int, float)) and v[-1] == '%': #2082 + pct = float(v[:-1]) + v = pct*value/100 + v = type(starting_value)(v) + + return v @VisiData.api def inputsingle(vd, prompt, record=True):