Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

55 Zeilen
3.8 KiB
TeX

The tool was developed as a terminal UI (TUI) as opposed to a graphical UI (GUI).
In order to function well in any type of console, two different modes have been developed.
The file \texttt{ddrescue\_tui.py} offers the CLI entry point and defines its arguments using \texttt{argparse}.
It decides which mode described in the following subsections is called,
either from the command line parameter \texttt{noninteractive} or by checking whether stdin is a tty.
\subsection{Non-interactive mode}\label{subsec:non-interactive-mode}
The non-interactive mode (see \vref{fig:tui_non-interactive}) only offers the function to visualise a map file.
The previously described functions for parsing and plotting are used to retrieve and plot image object.
This object is then printed to the terminal using the module \texttt{rich\_pixels}.
There are two methods in this module to print images, one from an image file and one from an image object.
However, the method to print from an image object does not implement the possibility to resize the image,
so it was necessary to use the protected method \texttt{Pixels.\_segments\_from\_image} which can handle the resizing.
The image is printed together with general status information and re-displayed at an interval
specified in command line arguments using an infinite loop and \texttt{time.sleep}.
\smimage[htbp,width=1\textwidth]{tui_non-interactive}{Non-interactive output of a mapfile}
\subsection{Interactive-mode}\label{subsec:interactive-mode}
The interactive mode offers a range of additional functions.
When called, you can specify whether a map file should be visualised (and at what initial interval) or
whether \texttt{ddrescue} should be started (including all associated parameters, root permissions are required here).
In addition, \texttt{ddrescue-tui} can also be started without further specifications.
The first tab of the interactive TUI (see \vref{fig:tui_interactive_1}) visualises a map file,
shows some additional status information from it and allows you to change the reload interval during runtime.
\smimage[htbp,width=1\textwidth]{tui_interactive_1}{Interactive output of a mapfile}
The second tab (see \vref{fig:tui_interactive_2}) is only available if the programme was executed with root privileges.
Here, \texttt{ddrescue} can be started with a form or the command of a running ddrescue is displayed here.
\smimage[htbp,width=1\textwidth]{tui_interactive_2}{Form to run ddrescue from the TUI}
Last but not least, the TUI offers both a light and a dark mode, which can be switched at runtime.
The interactive TUI code is split in two additional files.
First of all, \texttt{ddrescue\_tui\_app.py} is called.
It defines the main TUI application using the \texttt{textual} framework\footnote{textual: \url{https://textual.textualize.io/}} and
implements all top-level functions that need access to different parts of the application, like e.g.\ listeners for buttons.
Also, the start of \texttt{ddrescue} is done here in the function \texttt{run\_ddrescue}.
The modules \texttt{queue} and \texttt{threading} are used to provide a non-blocking IO
reading from stdout of the \texttt{ddrescue} process started with the modules \texttt{subprocess}.
Last but not least, \texttt{ddrescue\_tui\_widgets.py} contains customized widgets of the \texttt{textual} framework.
The \texttt{StatusWidget} utilizes the frameworks reactive attributes,
that trigger a redraw of a widget when the attribute changes,
to display and update status information.
The \texttt{PixelWidget} allows to display a simplified image on the console using the module \texttt{rich-pixels}\footnote{rich-pixels: \url{https://github.com/darrenburns/rich-pixels}}
which is also developed by the \texttt{textual} developers.
It uses the same mathod as described in \vref{subsec:non-interactive-mode} to regularly draw the plot into the widget.