From e945a98c5494f988bc9b22142c7c588473f08f02 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sun, 9 Apr 2023 01:35:05 -0400 Subject: [PATCH] feat: Complete row height implementation Now all parts of spreadsheet respond to the -F command line argument in fteapot, and row heights are computed in terms of the resulting character size. There is a new menu option for setting row heights in fteapot. Documentation is updated, and keybindings are made more uniform between teapot and fteapot and more fully documented. Resolves #57. --- NEWS | 6 +- doc/teapot.lyx | 193 ++++++++++++++++++++++++++++++++++----- src/CMakeLists.txt | 8 +- src/common/main.c | 4 +- src/display.c | 4 +- src/fteapot.fl | 130 +++++++++++++++----------- src/tools/interpolate.py | 39 ++++++++ teapot.1 | 2 + 8 files changed, 307 insertions(+), 79 deletions(-) create mode 100644 src/tools/interpolate.py diff --git a/NEWS b/NEWS index 4cafdd8..ca83cdd 100644 --- a/NEWS +++ b/NEWS @@ -11,19 +11,20 @@ o Comparison operators return bool rather than int (Note this can be a breaking change; you may need to wrap comparisons in int() if you are using the result in a numerical computation.) o Foreground and background color style attributes for cells. +o Variable row height for cells. o Addition of a find() macro to search for a cell satisfying a condition. o Addition of an is(VALUE, TYPE, TYPE,...) predicate o Addition of functions for unit displacements in the six cardinal directions (left, right, up, down, above, below) o TPA is now the default file format -o Addition of hexact float format, which allow for exact round trips to ASCII +o Addition of hexact float format, which allows for exact round trips to ASCII o New token type: funcall (which basically amounts to an expression). This allows parsed rather than unparsed expressions to be stored in cells, and allows macros which receive their arguments unevaluated. o sum(), min(), and max() can now operate over their list of arguments as well as over a block. o Added floor(), ceil(), trunc(), and round() functions for finding integers - associated with doubles, eiminating (note possible breaking change) the + associated with doubles, eliminating (note possible breaking change) the int conversion with two rounding directions. o Precedence of unary "-" made lower than exponentiation "^" to match Python; note possible breaking change. @@ -34,6 +35,7 @@ o Fill With operation for quickly filling the selected block with a single cell. o Additional arithmetic operations on locations. o Documentation better aligned with current behavior. o Additional key commands for clocking/resetting the sheet. +o New -F command line argument to set the overall font size for fteapot. Bug fixes: o Occasional early coredumps of teapot have been eliminated. diff --git a/doc/teapot.lyx b/doc/teapot.lyx index d7ea182..cd3ebc0 100644 --- a/doc/teapot.lyx +++ b/doc/teapot.lyx @@ -1144,7 +1144,7 @@ Up \begin_inset Text \begin_layout Plain Layout -[+] ++ \end_layout \end_inset @@ -1264,7 +1264,7 @@ To last column \begin_inset Text \begin_layout Plain Layout -[<] +< \end_layout \end_inset @@ -1293,7 +1293,7 @@ To row 0 \begin_inset Text \begin_layout Plain Layout -[>] +> \end_layout \end_inset @@ -1322,7 +1322,7 @@ To last row \begin_inset Text \begin_layout Plain Layout -[_ (Underscore)] +_ (Underscore) \end_layout \end_inset @@ -1351,7 +1351,7 @@ To Layer 0 \begin_inset Text \begin_layout Plain Layout -[*] +* \end_layout \end_inset @@ -1371,7 +1371,7 @@ To last layer \begin_inset Text \begin_layout Plain Layout - +{Ctrl-Right} \end_layout \end_inset @@ -1400,7 +1400,7 @@ Jump one page right \begin_inset Text \begin_layout Plain Layout - +{Ctrl-Left} \end_layout \end_inset @@ -1550,7 +1550,7 @@ status open \begin_layout Plain Layout \begin_inset Tabular - + @@ -1620,7 +1620,7 @@ Operation \begin_inset Text \begin_layout Plain Layout -F10 +[F10] {Menu bar always shown} \end_layout \end_inset @@ -1802,6 +1802,35 @@ Activate File menu \begin_inset Text +\begin_layout Plain Layout +{Meta-B} +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +Activate Block menu +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + +\begin_inset Text + \begin_layout Plain Layout {Meta-V} \end_layout @@ -1848,11 +1877,11 @@ Activate fOrmat menu - + \begin_inset Text \begin_layout Plain Layout - +F1 \end_layout \end_inset @@ -1861,7 +1890,7 @@ Activate fOrmat menu \begin_inset Text \begin_layout Plain Layout -{Meta-H} + \end_layout \end_inset @@ -1870,7 +1899,7 @@ Activate fOrmat menu \begin_inset Text \begin_layout Plain Layout -Activate Help menu +Show help \end_layout \end_inset @@ -1910,7 +1939,7 @@ Redraw screen \begin_inset Text \begin_layout Plain Layout - +{Esc} \end_layout \end_inset @@ -1919,7 +1948,7 @@ Redraw screen \begin_inset Text \begin_layout Plain Layout -[Ctrl-C] [Ctrl-G] {Esc} +[Ctrl-C] [Ctrl-G] \end_layout \end_inset @@ -2002,7 +2031,7 @@ status open \begin_layout Plain Layout \begin_inset Tabular - + @@ -2430,7 +2459,7 @@ Set cell label - + \begin_inset Text \begin_layout Plain Layout @@ -2443,7 +2472,7 @@ Set cell label \begin_inset Text \begin_layout Plain Layout -{Meta-B} +{Ctrl-D} \end_layout \end_inset @@ -2452,7 +2481,7 @@ Set cell label \begin_inset Text \begin_layout Plain Layout -Toggle cell/block bold +Toggle cell/block dim \end_layout \end_inset @@ -2472,7 +2501,65 @@ Toggle cell/block bold \begin_inset Text \begin_layout Plain Layout -{Meta-U} +{Ctrl-B} +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +Toggle cell/block bold +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +{Ctrl-I} +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +Toggle cell/block italic +\end_layout + +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +{Ctrl-U} \end_layout \end_inset @@ -2629,6 +2716,35 @@ Set cell/block precision Set column width \end_layout +\end_inset + + + + +\begin_inset Text + +\begin_layout Plain Layout + +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +{Meta-H} +\end_layout + +\end_inset + + +\begin_inset Text + +\begin_layout Plain Layout +Set row height +\end_layout + \end_inset @@ -2753,7 +2869,7 @@ Reset sheet \begin_inset Text \begin_layout Plain Layout -F9, {Shift-Tab} +F8, F9, {Shift-Tab} \end_layout \end_inset @@ -3452,7 +3568,7 @@ ignored. \end_layout \begin_layout Standard -In addition, each column has a width. +In addition, each column has a width and each row has a height. \end_layout \begin_layout Subsubsection @@ -3503,6 +3619,39 @@ The column width only affects the screen display, not the formatting of It is intended to let you make better usage of the screen for more overview. If the width is too small to display the cell value, a placeholder will be displayed. + The column width is measured in +\begin_inset Quotes eld +\end_inset + +characters, +\begin_inset Quotes erd +\end_inset + + which are exact in the console and correspond to an arbitrary notional + character width in the graphical version, where the actual number of characters + that fit in a cell of a given width will depend on the font and size. +\end_layout + +\begin_layout Subsubsection +Row Height +\end_layout + +\begin_layout Standard +Similar comments apply to the row height as to the column width. + An important difference is that row heights are expressed in +\begin_inset Quotes eld +\end_inset + +twelfths of a character. +\begin_inset Quotes erd +\end_inset + + This means that in the console version, all row heights upt to 23 are displayed + as a single-character-high row; heights 24 to 35 are shown as two characters + high; and so on. + In the graphical version, of course, the actual row height is proportional + to the specified value, with a height of 12 able to display one full-height + character. \end_layout diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 367b198..d654e1a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,9 +39,15 @@ endif () find_package(FLTK) if (FLTK_FOUND) + find_program(PYTHON python3 python) fltk_wrap_ui(fteapot fteapot.fl) include_directories(${FLTK_INCLUDE_DIR}) - add_executable(fteapot WIN32 tpt_choose.cxx ${fteapot_FLTK_UI_SRCS}) + add_executable(fteapot WIN32 tpt_choose.cxx ${CMAKE_CURRENT_BINARY_DIR}/fteapot.h ${CMAKE_CURRENT_BINARY_DIR}/fteapot_interpolated.cxx) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fteapot_interpolated.cxx + COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/tools/interpolate.py ${CMAKE_CURRENT_SOURCE_DIR}/fteapot.fl ${CMAKE_CURRENT_BINARY_DIR}/fteapot.cxx + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/fteapot.cxx ${CMAKE_CURRENT_SOURCE_DIR}/tools/interpolate.py + ) target_compile_options(fteapot PRIVATE -Wno-shadow -Wno-conversion -Wno-sign-conversion) set(fteapot_DEB_DEPENDS ", libstdc++6 (>= 4.1.1), libfltk1.3") if (ENABLE_HELP) diff --git a/src/common/main.c b/src/common/main.c index dd4aef0..0b49da1 100644 --- a/src/common/main.c +++ b/src/common/main.c @@ -1548,13 +1548,13 @@ int do_sheetcmd(Sheet *cursheet, Key c, bool moveonly) "\n" "

Original Version: Michael Haardt
\n" "Current Maintainer: Joerg Walter
\n" - "Contibutions by: Glen Whitney
\b" + "Contributions by: Glen Whitney
\b" "Home Page: http://www.syntax-k.de/projekte/teapot/

\n" "This distribution: https://code.studioinfinity.org/glen/teapot-spreadsheet/

\n" "\n" "

Copyright 1995-2006 Michael Haardt,
\n" "Copyright 2009-2010 Joerg Walter (info@syntax-k.de)
" - "Copyright 2019 Glen Whitney

\n" + "Copyright 2019,2023 Glen Whitney

\n" "\f" "

This program is free software: you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" diff --git a/src/display.c b/src/display.c index d6e08b4..d0c28f8 100644 --- a/src/display.c +++ b/src/display.c @@ -1123,7 +1123,9 @@ static Key wgetc(void) /* Control R, recalculate sheet */ case '\022': return K_RECALC; - /* Control S, clock sheet */ + /* F8, F9 or Control S, clock sheet */ + case KEY_F(8): + case KEY_F(9): case '\023': return K_CLOCK; /* Control X, get one more key */ diff --git a/src/fteapot.fl b/src/fteapot.fl index f6d255f..953b1ce 100644 --- a/src/fteapot.fl +++ b/src/fteapot.fl @@ -1,4 +1,12 @@ # data file for the Fltk User Interface Designer (fluid) +# Code replacements for dummy numerical constants: +# 9999100/*fontsize*/ +# 9999112/*fontsize + 12*/ +# 9999114/*fontsize + 14*/ +# 9999110/*fontsize + 10*/ +# 9999224/*2*fontsize + 24*/ +# 99990336/*600 - 3*fontsize - 36*/ +# 99990112/*600 - fontsize - 12*/ version 1.0300 header_name {.h} code_name {.cxx} @@ -320,6 +328,8 @@ class TeapotTable {open : {public Fl_Table}} case FL_Escape: k = K_INVALID; break; case FL_BackSpace: k = K_BACKSPACE; break; case FL_F+1: k = ctrl?K_ABOUT:K_HELP; break; + case FL_F+2: k = K_LOADMENU; break; + case FL_F+3: k = K_SAVE; break; case FL_F+8: k = ctrl?K_RECALC:K_CLOCK; break; case FL_F+9: k = ctrl?K_RECALC:K_CLOCK; break; case FL_F+10: k = (Key)'/'; break; @@ -389,14 +399,14 @@ class TeapotTable {open : {public Fl_Table}} case FL_Page_Up: k = shift ? K_PSHEET : ctrl ? K_FIRSTL : K_PPAGE; break; + default: + /* Handle shifted keys */ + if (Fl::event_length() == 1) k = (Key)(Fl::event_text()[0]); } + /* This short circuit perhaps needs an explanation: */ if (k > 0 && (ctrl || alt)) return 0; - // Quick and dirty upper-case fix, fails for international chars on keyboards... - if (shift && !alt && !ctrl && k >= 'a' && k <= 'z') - k = (Key)(k - 'a' + 'A'); - do_sheetcmd(cursheet, k, cursheet->moveonly); do_callback(ACTION, 0, 0); redraw(); @@ -440,6 +450,8 @@ class TeapotTable {open : {public Fl_Table}} //printf(" : t: %i, w: %i, p: %i, r: %i\\n", tow, w, xpos, x2+1); cols(x2+1); } + visible_cells(y1, y2, x1, x2); + cursheet->width = x2 - x1 + 1; if (y2+2 < rows() && (size_t)rows() > cursheet->dim[Y]) rows((size_t)y2+2 < cursheet->dim[Y] ? cursheet->dim[Y] : y2+2); @@ -492,218 +504,229 @@ class MainWindow {open} table->update_table(); table->redraw(); } - open xywh {0 0 800 25} class Fl_Sys_Menu_Bar + open xywh {0 0 800 9999112} class Fl_Sys_Menu_Bar + code0 { + menu->textsize(fontsize); + } } { - Submenu {} {label {&File} xywh {25 25 67 24} } { + Submenu {} {label {&File} xywh {25 25 67 24} labelsize 0 } { MenuItem {} { label {&Open...} user_data K_LOADMENU - xywh {5 5 30 20} shortcut 0x4006f + xywh {5 5 30 20} labelsize 0 shortcut 0x4006f } MenuItem {} { label {&Save} user_data K_SAVE - xywh {0 0 30 20} shortcut 0x40073 + xywh {0 0 30 20} labelsize 0 shortcut 0x40073 } MenuItem {} { label {Save &As...} user_data K_NAME - xywh {0 0 30 20} shortcut 0x50053 divider + xywh {0 0 30 20} labelsize 0 shortcut 0x50053 divider } MenuItem {} { label {&Quit} user_data K_QUIT - xywh {0 0 30 20} shortcut 0x40071 + xywh {0 0 30 20} labelsize 0 shortcut 0x40071 } } - Submenu {} {label {&Block} xywh {25 25 67 24} } { + Submenu {} {label {&Block} xywh {25 25 67 24} labelsize 0 } { MenuItem {} { label {&Insert} user_data BLOCK_INSERT - xywh {0 0 30 20} shortcut 0x90069 + xywh {0 0 30 20} labelsize 0 shortcut 0x90069 } MenuItem {} { label {&Delete} user_data BLOCK_DELETE - xywh {0 0 30 20} shortcut 0x90064 divider + xywh {0 0 30 20} labelsize 0 shortcut 0x90064 divider } MenuItem {} { label {&Move} user_data BLOCK_MOVE - xywh {0 0 30 20} shortcut 0x9006d + xywh {0 0 30 20} labelsize 0 shortcut 0x9006d } MenuItem {} { label {&Copy} user_data BLOCK_COPY - xywh {0 0 36 21} shortcut 0x90063 divider + xywh {0 0 36 21} labelsize 0 shortcut 0x90063 divider } MenuItem {} { label {&Fill} user_data BLOCK_FILL - xywh {0 0 36 21} shortcut 0x90066 + xywh {0 0 36 21} labelsize 0 shortcut 0x90066 } MenuItem {} { label {FillWith} user_data FILL_BLOCK - xywh {0 0 36 30} - } + xywh {0 0 36 30} labelsize 0 } MenuItem {} { label {C&lear} user_data BLOCK_CLEAR - xywh {0 0 36 21} shortcut 0x9006c divider + xywh {0 0 36 21} labelsize 0 shortcut 0x9006c divider } MenuItem {} { label {&Sort} user_data BLOCK_SORT - xywh {0 0 36 21} shortcut 0x90073 + xywh {0 0 36 21} labelsize 0 shortcut 0x90073 } MenuItem {} { label {Mi&rror} user_data BLOCK_MIRROR - xywh {0 0 36 21} shortcut 0x90072 + xywh {0 0 36 21} labelsize 0 shortcut 0x90072 } } - Submenu {} {label {&View} xywh {0 0 70 21}} { + Submenu {} {label {&View} xywh {0 0 70 21} labelsize 0 } { MenuItem {} { label {Column &Width...} user_data K_COLWIDTH - xywh {0 0 36 21} shortcut 0x80077 + xywh {0 0 36 21} labelsize 0 shortcut 0x80077 + } + MenuItem {} { + label {Row &Height...} + user_data K_ROWHEIGHT + xywh {0 0 36 21} labelsize 0 shortcut 0x80068 } MenuItem {} { label {&Goto} user_data K_GOTO - xywh {0 0 36 21} shortcut 0x40067 + xywh {0 0 36 21} labelsize 0 shortcut 0x40067 } } - Submenu {} {label {F&ormat} open xywh {5 5 70 21}} { + Submenu {} {label {F&ormat} open xywh {5 5 70 21} labelsize 0 } { MenuItem {} { label {L&abel...} user_data ADJUST_LABEL - xywh {0 0 36 21} shortcut 0x80061 divider + xywh {0 0 36 21} labelsize 0 shortcut 0x80061 divider } MenuItem dim { label {&Dim} user_data ADJUST_DIM - protected xywh {0 0 34 21} + protected xywh {0 0 34 21} labelsize 0 shortcut 0x40064 code0 {o->flags |= FL_MENU_TOGGLE;} } MenuItem bold { label {&Bold} user_data ADJUST_BOLD - protected xywh {0 0 34 21} shortcut 0x80062 + protected xywh {0 0 34 21} labelsize 0 shortcut 0x40062 code0 {o->flags |= FL_MENU_TOGGLE;} } MenuItem italic { label {&Italic} user_data ADJUST_ITALIC - protected xywh {0 0 34 21} + protected xywh {0 0 34 21} labelsize 0 shortcut 0x40069 code0 {o->flags |= FL_MENU_TOGGLE;} } MenuItem underline { label {&Underline} user_data ADJUST_UNDERLINE - protected xywh {0 0 34 21} shortcut 0x80075 divider + protected xywh {0 0 34 21} labelsize 0 shortcut 0x40075 + divider code0 {o->flags |= FL_MENU_TOGGLE;} } MenuItem left { label {&Left} user_data ADJUST_LEFT - protected xywh {0 0 36 21} shortcut 0x8006c + protected xywh {0 0 36 21} labelsize 0 shortcut 0x8006c code0 {o->flags |= FL_MENU_RADIO;} } MenuItem right { label {&Right} user_data ADJUST_RIGHT - protected xywh {0 0 36 21} shortcut 0x80072 + protected xywh {0 0 36 21} labelsize 0 shortcut 0x80072 code0 {o->flags |= FL_MENU_RADIO;} } MenuItem center { label {&Center} user_data ADJUST_CENTER - protected xywh {0 0 36 21} shortcut 0x80063 divider + protected xywh {0 0 36 21} labelsize 0 shortcut 0x80063 + divider code0 {o->flags |= FL_MENU_RADIO;} } MenuItem {} { label {&Precision...} user_data ADJUST_PRECISION - xywh {0 0 36 21} shortcut 0x80070 + xywh {0 0 36 21} labelsize 0 shortcut 0x80070 } MenuItem {} { label {&Foreground...} user_data ADJUST_FOREGROUND - xywh {0 0 36 21} + xywh {0 0 36 21} labelsize 0 } MenuItem {} { label {&Background...} user_data ADJUST_BACKGROUND - xywh {0 0 36 21} divider + xywh {0 0 36 21} labelsize 0 divider } menuitem dec { label {&Decimal} user_data ADJUST_DECIMAL - protected xywh {0 0 36 21} + protected xywh {0 0 36 21} labelsize 0 code0 {o->flags |= FL_MENU_RADIO;} } MenuItem sci { label {&Scientific} user_data ADJUST_SCIENTIFIC - protected xywh {0 0 36 21} shortcut 0x80073 + protected xywh {0 0 36 21} labelsize 0 shortcut 0x80073 code0 {o->flags |= FL_MENU_RADIO;} } MenuItem cpt { label {Co&mpact} user_data ADJUST_COMPACT - protected xywh {0 0 36 21} + protected xywh {0 0 36 21} labelsize 0 code0 {o->flags |= FL_MENU_RADIO;} } MenuItem hex { label {He&xact} user_data ADJUST_COMPACT - protected xywh {0 0 36 21} divider + protected xywh {0 0 36 21} labelsize 0 divider code0 {o->flags |= FL_MENU_RADIO;} } MenuItem shadow { label {Shadow&ed} user_data ADJUST_SHADOW - protected xywh {0 0 36 21} shortcut 0x80065 + protected xywh {0 0 36 21} labelsize 0 shortcut 0x80065 code0 {o->flags |= FL_MENU_TOGGLE;} } MenuItem transparent { label {&Transparent} user_data ADJUST_TRANSPARENT - protected xywh {0 0 36 21} shortcut 0x80074 divider + protected xywh {0 0 36 21} labelsize 0 shortcut 0x80074 + divider code0 {o->flags |= FL_MENU_TOGGLE;} } MenuItem lock { label {Lo&ck} user_data ADJUST_LOCK - protected xywh {0 0 36 21} shortcut 0x80063 + protected xywh {0 0 36 21} labelsize 0 shortcut 0x80063 code0 {o->flags |= FL_MENU_TOGGLE;} } MenuItem ignore { label {&Ignore} user_data ADJUST_IGNORE - protected xywh {0 0 36 21} shortcut 0x80069 + protected xywh {0 0 36 21} labelsize 0 shortcut 0x80069 code0 {o->flags |= FL_MENU_TOGGLE;} } } - Submenu {} {label {&Help} open xywh {25 25 67 24}} { + Submenu {} {label {Help} open xywh {25 25 67 24} labelsize 0 } { MenuItem {} { label {&Manual} user_data K_HELP - xywh {0 0 30 20} shortcut 0xffbe + xywh {0 0 30 20} labelsize 0 shortcut 0xffbe } MenuItem {} { label {&About} user_data K_ABOUT - xywh {0 0 30 20} + xywh {0 0 30 20} labelsize 0 } } } Fl_Group line_label { label { Input:} open - protected xywh {0 25 800 25} box ROUND_UP_BOX align 20 deactivate + protected xywh {0 9999112 800 9999112} labelsize 9999100 + box ROUND_UP_BOX align 20 deactivate } { Fl_Input line_input { @@ -717,8 +740,12 @@ class MainWindow {open} line_label->deactivate(); } } - protected xywh {75 27 723 21} box ROUND_DOWN_BOX + protected xywh {75 9999114 723 9999110} box PLASTIC_DOWN_BOX + labelsize 9999100 labeltype NO_LABEL align 20 when 6 deactivate + code0 { + line_input->textsize(fontsize); + } } } Fl_Box table { @@ -802,14 +829,15 @@ class MainWindow {open} case FLT_NO_FORMAT: ; } } - protected xywh {0 50 800 525} box DOWN_FRAME + protected xywh {0 9999224 800 99990336} box DOWN_FRAME labeltype NO_LABEL resizable code0 { table->sheet(sheet); } class TeapotTable } Fl_Box status { label {teapot ready.} - protected xywh {0 575 800 25} box GTK_ROUND_DOWN_BOX align 20 + protected xywh {0 99990112 800 9999112} + box GTK_ROUND_DOWN_BOX align 20 } } code { current = this; diff --git a/src/tools/interpolate.py b/src/tools/interpolate.py new file mode 100644 index 0000000..9792c58 --- /dev/null +++ b/src/tools/interpolate.py @@ -0,0 +1,39 @@ +# To get around the fact that fluid only allows numerical constants +# in some places that expressions would be preferred, this +# file takes a fluid file which may contain numerical constants of the form +# +# 9999NNN/*REPLACEMENT*/ +# +# where the NNN are distinct digit sequences (of any length) +# and the corresponding fluid output and replaces any 9999NNN in the output +# with REPLACEMENT (which can of course be any text). Note that the +# entire numerical constant with its replacement comment must occur within +# a single line of the fluid file. The result is written +# to a new output file with the literal string `_interpolated` interpolated +# before its extension. + +from pathlib import Path +import re +import sys + +fluidin = sys.argv[1] +genfile = Path(sys.argv[2]) +outfile = genfile.with_stem(genfile.stem + '_interpolated') + +# First collect all of the replacements from the fluidfile +replacerPattern = re.compile(r"(9999\d*)/[*](.*)[*]/") +replacement = {} +with open(fluidin) as fluidf: + for line in fluidf: + foundpat = replacerPattern.search(line) + if foundpat: + replacement[foundpat[1]] = foundpat[2] + +# Now make all replacements in the generated file +with open(outfile, 'w') as outf: + with open(genfile) as genf: + for line in genf: + line = line[:-1] + for key in replacement: + line = line.replace(key, replacement[key]) + print(line, file=outf) diff --git a/teapot.1 b/teapot.1 index 70ad9b5..f5b9fbe 100644 --- a/teapot.1 +++ b/teapot.1 @@ -62,6 +62,8 @@ Display strings definitely NOT quoted or definitely quoted, respectively. Redraw the terminal window more often. .It Fl p Ar digits Set default precision of displayed numbers. +.It Fl F Ar digits +Set the general font size on pixels (fteapot only). .El .\" .\"