Summarized using AI

Exploring Reline: Enhancing Command Line Usability

Mari Imaizumi • November 15, 2024 • Chicago, IL • Talk

The video titled "Exploring Reline: Enhancing Command Line Usability" features Mari Imaizumi at RubyConf 2024, focusing on Reline, a pure Ruby implementation of GNU Readline. Reline improves command line interactions by allowing users to configure command line behavior through the .inputrc file, similar to GNU Readline, while aiming for compatibility with it and enhancing usability. Mari introduces the functionalities and compares Reline's features with GNU Readline, detailing its capabilities and shortcomings.

Key Points Discussed:

- Overview of IRB: Mari explains the Interactive Ruby (IRB) environment, which allows input of Ruby code and displays the results while providing features like suggestion dialogues via the Tab key.

- Introduction to Reline: Reline is introduced as a command line editor managing user input more efficiently than traditional methods. This eliminates issues like awkward escape sequences during typographical errors. Mari demonstrates Reline's capability of managing input and cursor positioning more intuitively.

- Comparison of Features:

- Reline supports basic operations like line editing, history navigation, and tab completion.

- Advanced features from GNU Readline, such as certain editing commands and configurations, are still lacking in Reline, making it seem like a limited version of Readline.

- Reline supports multi-line input and customizable input decorations, aiming to enhance user experience.

- Configuration through .inputrc: Mari discusses how users can configure their command line experience via the .inputrc file, showing the challenges and gaps in feature sets between Reline and GNU Readline.

- Implementation of Missing Features: The video covers recent updates and features added to Reline, such as the undo function and handling different editing modes (Emacs and Vi), demonstrating how these features can significantly enhance usability.

The presentation concludes with Mari expressing the aim for Reline to be the preferred choice for command line usage among Ruby users, promoting community involvement in feature requests and improvements. Overall, Reline is portrayed as a powerful tool for enhancing command line usability while striving to meet and exceed the capabilities found in GNU Readline.

Exploring Reline: Enhancing Command Line Usability
Mari Imaizumi • November 15, 2024 • Chicago, IL • Talk

Reline is a pure Ruby implementation of GNU Readline and IRB uses it.
GNU Readline allows you to write configuration in .inputrc, and Reline reads this
configuration file and sets key bindings. However, there are many things that
GNU Readline can do that Reline cannot. This session will introduce those features
and talk about their implementation in Reline.

RubyConf 2024

00:00:15.360 thank you for the kind introduction hello everyone I'm excited to be here
00:00:20.800 and share my work with you today uh I I want to introduce luik GI
00:00:29.640 mat introduce
00:00:34.960 shortly next L Ki will be held in my hometown Aim so please join us also
00:00:42.120 today's presentation is almost almost the same as my talk at Luby Ki this year
00:00:47.760 so I hope you can get a feel for it today's main topic is Ry but before
00:00:54.199 that let me explain a bit about IRB most of you must have used before
00:01:02.160 right thank you Irv stands for interactive Ruby and it is Ruby's
00:01:08.720 default Leo Leo stands for read eval print Loop which means you can input
00:01:14.600 Ruby code IRB evaluates it and output the result you can learn it using the
00:01:21.200 IRB command it is also used as a default label for the ls
00:01:26.960 console for example when you learn
00:01:38.479 IRB 3
00:01:43.640 a when you Irv and type is
00:01:49.600 equal L comp the string T that when you present
00:01:56.680 the result Will C is displayed if you call a method on
00:02:01.880 S and a completion dialog appears by default you can move through the
00:02:08.160 suggestion by pressing tab the method documentation is also shown the plump
00:02:14.800 display IRB main under the line
00:02:22.920 number back to the
00:02:28.160 slide IB something we use but do you know how it works in simple term this is
00:02:35.879 how it works when you learn the ilb command line starts up display the
00:02:41.440 prompt and waits for user input once a Val be called segment is entered it is
00:02:48.120 sent to IRB for evaluation and the result is displayed on the
00:02:53.239 terminal IRB learns a code analyze it and applies color formatting
00:03:00.080 in the image IRB recognize Ruby comp as a string and colors it accordingly IRB
00:03:07.519 evaluate the line S equal the count on the second line we input s. ask only
00:03:14.440 since s is a string the suggestions include a only a string method the
00:03:20.480 component responsible for showing these suggestions is leel type completer if
00:03:26.360 LEL type complet is not installed IB handle the suggestions the documentation
00:03:32.480 for aski only appears on the light and is generated using
00:03:37.799 alook so what does the line handle it manages the display and the handling of
00:03:43.920 lines while typing theine is responsible for showing the plum the CLE after
00:03:50.360 asking only and the dialog boxes you can think the line as the front end on the
00:03:57.519 terminal and IRB as a back both IB and line are default GS in the
00:04:04.319 3.3 I am one of the committers for this projects my name is Mari maumi I work at
00:04:12.040 St Inc where I develop Le applications my pron of heart this is my first time
00:04:18.280 in the US and my first time presenting English so I'm
00:04:30.160 thank you for being here and please feel free to come and say hi so let's get
00:04:36.960 back to the main topic enhancing Line's features first I'll explain what a
00:04:42.520 command line editor like line does of its capabilities next I'll compare line
00:04:48.919 with with G read line as one of Line's goal is to maintain compatibility with
00:04:54.880 it finally I'll explain the design and implementation of and the feature I
00:05:00.880 worked on I hope to share what line aims to achieve and what it can do so what is
00:05:08.639 line the line is a command line editor here a command line editor refers to
00:05:14.400 software that lears on Terminal emulators and handles user input
00:05:19.479 although command line editor isn't a common term um I'm using it here because
00:05:25.479 there isn't a generic time for software like G read line example include G read
00:05:30.919 line and exit liit the line aims to be compatible with these
00:05:37.520 libraries when I say a command line editor handles user input but it might
00:05:42.840 be hard to picture so let's take a look at what what happens without a command line editor here are three lines of the
00:05:50.319 we code this program display please enter your name which for user input and
00:05:56.319 print the the enter name when you press ENT wait
00:06:09.080 see so this one
00:06:16.000 I this one RV okay U now when we learn
00:06:21.520 the program it waits for input so let's try entering my name I mean to type
00:06:30.960 Mar IM
00:06:36.199 oh but I mistakenly typed
00:06:41.560 hard to fix this typo I press the left Al key but instead of uh M the castle a
00:06:51.039 strange set of characters appeared this is an an escape sequence representing a
00:06:56.639 CLE action I wanted to move the CLE B but didn't work as expected and the
00:07:03.639 escape sequence was displayed
00:07:15.039 instead let's try using line it's simple to use just require line and use LINE Le
00:07:22.120 line similar to how get works the read line method accepts a single line of
00:07:34.720 to okay uh test to
00:07:42.360 RB use reine
00:07:54.800 a and I made my type again this time
00:07:59.960 I press the left out key to move back and
00:08:05.199 Mari IM to me yeah and I was able to
00:08:12.319 successfully to change the castle position and correct the mistake this is
00:08:18.400 because the line handles the escape sequence and moves Castle back changing
00:08:24.800 the castle position on the terminal isn't automatic in this script the line
00:08:30.639 processes the escape sequence received from the terminal and adjust the CLE
00:08:39.120 position okay thank
00:08:47.360 you uh a command line editor provides a set of operations for editing text like
00:08:53.560 moving the castle in tools like Irv or bash the Hing of input key is is done by
00:09:00.800 the command line editor not by IRB or bash itself let me introduce some command
00:09:08.640 line editors the most widely used one is G read line which using in bash IRB up
00:09:15.519 to Ruby 2.6 and GDB there's also a library called edit line which comes
00:09:22.120 standard with mest the line has been used in IRB starting from Ruby 2.7 and
00:09:29.079 is also used in tools like the deak gem Highline and
00:09:34.600 hexia now let's look at the features of G read line a wellknown command line
00:09:39.959 editor the first feature is line editing which includes basic operations like
00:09:45.079 moving the CLE next is history editing which allows you to navigate through the
00:09:50.680 command line history using the the app alow key there's also an old complete
00:09:57.040 feature such as pressing the Tab Key in bash complete a file name this is
00:10:02.079 provided by lead line lead line also offers editing commands such as pressing
00:10:08.440 contrl a to move to the beginning of the line and control e to move to the end
00:10:14.480 additionally it supports M macros and various customizations through the the
00:10:20.160 input RC file since m l Lin go to be compatible with read lines let's do a
00:10:26.880 quick feature comparison the line can can be most of the basic operations that
00:10:32.079 g read line can such as line editing history navigation and op completion
00:10:38.320 however it still La some Advanced features like editing commands and certain configuration that can be set
00:10:44.680 through input Ry which I will explain later from the comparison a line may
00:10:51.360 seem like a less capable version version of good read line so let me add that
00:10:57.480 there are some powerful to whole features unique to theine P it can be
00:11:03.040 display dialogues uh such as completion dialogues second theine supports to
00:11:09.000 multi support multiline input including plumps plumps while multi-line input is
00:11:15.880 also possible with G read line the line Hing with proms makes it easier to use
00:11:22.519 third line is extensible Lu Luby you can customize input line decorations
00:11:29.880 dialogues completion suggestions and termination conditions for matal input
00:11:35.399 using lby procs the line aims to be compatible with G read line but as shown earlier
00:11:43.120 some features are missing this include editing commands key binding for those
00:11:48.680 commands and toal options occasionally users report issues about features
00:11:55.240 features available in Le line but not in the line showing that these features
00:12:00.720 would be appreciated Additionally the line is increasingly expected to be compatible
00:12:07.519 with lead line starting from the 3.3 lead line X was removed from the default
00:12:15.240 gems so when L line X isn't available require lad line will automatically use
00:12:22.480 fine this change solves the issue of insulation problems with lead line
00:12:28.680 during be build however users may unknowingly switch their dependency from
00:12:35.120 Le line X to theine increasing the need for the line's compatibility
00:12:41.560 features the issue where require lead line CA the line can be resolved by
00:12:47.240 installing the line X but as a maintainer I hope you user chose the
00:12:53.800 line over lead line X I want the line to work seamlessly when users switches from
00:13:01.079 when you read line without noticing any difference I also hope that theine
00:13:06.880 beames to be to theine becames the prefer choice for users considering
00:13:14.000 switches their command line editor for example in Pride a p for supporting the
00:13:20.639 line has been marged into the master blunch so to summarize the challenges so
00:13:26.880 far line aims for compet ility with read line so more compatibility is desired
00:13:33.360 additionally it should work simly when require lead line is used so what
00:13:39.720 specific are Miss specific features are missing let's take a closer look at the
00:13:45.560 feature gaps between the line and read line by the way has anyone here ever
00:13:52.519 written on input RC file please L your hand if you have oh
00:13:59.839 10 10 five uh fewer than expected thank
00:14:08.040 you input RC is a configuration file both lead line and the line can Le input
00:14:15.199 RC RC it is typically loaded from your home directory or from a location
00:14:22.519 specified by an environment variable in input RC you can set total of options
00:14:28.440 editing key bindings and choose between emox mode or V
00:14:34.040 mode lead line and L line have to editing mod Emax mode and VI mode the
00:14:40.120 default is Emax mode VI mode has both command command mode and is mode but not
00:14:46.800 all VI functions are available only simple commands are implemented to
00:14:51.880 switch to VI mode you need to add a setting to your input RC
00:14:57.000 file input RC is a file that can be written using syntax like this the first
00:15:04.120 line says show mod impr prompt on is a setting to display the current editing
00:15:10.480 mode in the prompt the second line set VI command mode string configure the
00:15:17.800 string display the front when VI is in command mode the third line follows a similar
00:15:25.519 pattern the first line is a Comm is comment it out uh anything after sh is
00:15:33.600 ignored as a comment L six starts an if statement you can specify software names
00:15:39.560 or modes in these conditions for theine you can use if Ruby or if the line in
00:15:46.040 this case it configures control e to execute emox editing mode only when the
00:15:52.120 line is used the setting on line 10 applies regardless of conditions by
00:15:58.360 default it is set to imox mode so this line are the key binding that switches
00:16:04.199 to VI mode when contrl s is pressed in imox mode defa key bindings are set within
00:16:13.040 the command line editor for example by default control a moves the
00:16:19.560 curle to the beginning of the line in VI mode these are separate key bindings for
00:16:25.680 command mode and insert mode while customization is possible through input
00:16:31.440 RC there are some setting that don't work with the line to understand which
00:16:37.160 features are missing I compared the line to read line to see what configuration
00:16:42.800 items are supported as of a 16 2024 nine supports 26% of variables and
00:16:52.000 44% of editing commands some configuration items like a like file
00:16:57.639 name comption are not supported by the line at all so while the coverage is still
00:17:05.000 slow it will be great to implement the features available in lead line but
00:17:11.839 missing in lead line however there are 1001 items including setting and
00:17:17.600 commands that have been implemented yet we need to start with the most important
00:17:23.679 ones and release them first to help prioritize I analyze input files to
00:17:30.440 files push to GitHub to see how frequently these setting are used so I
00:17:36.600 look at the usage to see how frequently each of one the
00:17:43.280 166 configurable item was set this included items were commented out so it
00:17:50.120 may not reflect exact usage numbers additionally for functions with default
00:17:56.559 key bindings actual usage is likely higher than the number of matches found
00:18:01.679 in found in total 6,600 input RC files were
00:18:09.080 examined here is a configuration item with high usage rate the top item
00:18:14.919 completion ignor case is a setting that makes Auto completion case incentive it
00:18:20.640 was found in 3,700 out of 6,600 files which shows it is quite
00:18:29.039 commonly used other frequently used setting include history search setting
00:18:34.240 that make t completion more convenient and basic key bindings configurations on the other hand some
00:18:41.600 items have a usage late of zero B out of 6600 indicating there are not used at
00:18:49.280 all we use information like usage late the presence of defa key bindings and
00:18:55.640 issues raised for line to decide which features to ment recently we've added
00:19:02.240 features like undo redo show if ambiguous change to editing mode
00:19:08.679 supports for mode conditions in input RC and support for bracketed past mode
00:19:14.880 Let's Take a look at the implementation of the and feature to understand how the
00:19:20.720 line operates from here we'll dive into thei
00:19:25.880 code first let's see what the line does when you input a next we look at what
00:19:34.360 happens when control a is pressed finally we'll go through implementing
00:19:40.640 the UND command let's start by seeing what
00:19:45.760 happens in the line when we laar this simple script it's just a program that
00:19:52.480 requires theine CA theine line and print the result with put
00:20:05.400 but this three are be dis
00:20:14.600 program when you input a and press Center a is displayed from this call
00:20:23.120 let's examine how line works
00:20:29.960 simply put line processes input this R initialization waiting for input Hing
00:20:37.080 input keys and lendering from here I show C in some of which are simplified
00:20:43.640 versions or included addit explanations during initialization
00:20:50.360 theine sets up various configurable blocks this input RC for configurations
00:20:56.720 and establish that default key bindings after initialization read iio
00:21:05.360 waits for key input from standard input from Le iio inet C is eventually
00:21:14.440 called and it weighs for input using iio weight readable when input is available
00:21:21.840 I get bite ites one bite at a time for example if you input the lowercase
00:21:29.360 letter A C will F the number
00:21:34.559 97 the received input is pass to line editor update for characters within seven bits
00:21:42.640 config editing mode get method is used to match the key to the corresponding
00:21:49.840 method for example in Max mode if the key is 97 the default key binding
00:21:57.240 assigns it insert to a then Ed insert is called it enal the
00:22:04.480 key which is a number into a string and pass it into inser text the insert text
00:22:12.120 method update the instance variables that manages the input text the
00:22:17.559 variables per Lines line index and V pointer up update this instance variables place an
00:22:25.400 important Lo within the line before L is an aray that holds the text being
00:22:32.000 intered in the case of multi-line input it contains multi-line multiple
00:22:37.919 elements The Prompt itself not included in this aray line index and by poter
00:22:44.840 represent the CLE position line index is used to calculate the y coordinate of
00:22:51.640 the CLE while bite pointer is used for the the x coordinate for example if the
00:22:59.600 input is if one 2 three and the castle is after the three bu far of lines will
00:23:07.840 contain if one and two and line index will be
00:23:13.480 two with the bu pointer at seven these values are used for
00:23:20.200 lendering and a is displayed on the screen if the end condition is met
00:23:26.120 lendering is completed and the input waiting Loop is exited if not it returns
00:23:32.840 waiting for input up to this point we have successfully input and display the
00:23:38.120 character a next let's use the same script and
00:23:44.120 input the contay command which moves the CLE to the beginning of the
00:23:50.679 line initialization and waiting for input works the same be as before and
00:23:57.480 when control a is pressed the key code one is input get method is then used to
00:24:04.520 match the key code to its corresponding method when control a is pressed the key
00:24:11.279 code is one so Ed move to beginning is called e mo to beginning says by pointer
00:24:19.320 which represent the the x coordinate of the CLE position to zero meaning the
00:24:26.039 beginning of the line after this the castle position is recalculated and
00:24:31.159 lered allowing the castle to move the start of the line the areas method
00:24:37.320 defined beginning of line and v z which are commands that can be specified in
00:24:43.720 inut SE although the names def they perform the same action so they group
00:24:50.000 using a
00:24:56.399 SE now let's if met undo although undo was not among the top features earlier
00:25:03.240 it is common function in most basic editors and it's useful to have in G read line pressing controlcore executes
00:25:11.120 undo so we implement it in theine to work similarly with control underscore
00:25:18.080 so what is undo undo is a function that we B previous actions however the way it
00:25:24.559 works very varies between editors in new R line for example it likely Leos
00:25:31.440 continuous key strok within a certain time frame as a single unit for undo
00:25:36.960 this mean if you type ABC and press undo the interior ABC is erased reverting to
00:25:45.440 the state before input in the Z line editor if you type ABC and press and do
00:25:53.320 it reverts to AB since the behavior in read line can be somewh unar the line
00:26:00.200 was implemented with the same approach as this year here is a simplified overview of
00:26:07.320 undo when action is performed it is save to the history conversely when UND is
00:26:15.799 executed one entry is poed from the history it sounds simple now let's
00:26:21.720 implement this in the line current line represents the line currently being edited on line is an LA
00:26:29.760 that manages history let's say a is entered this is added to the current
00:26:36.600 line and the previous line is St As Old Line when you want to undo you need to
00:26:43.919 rever to the state before the current line so the old line data is pushed to
00:26:49.440 pass lines next and B is entered the current line which had a now
00:26:57.120 becomes a the old line keeps the previous state which is a the old line
00:27:03.520 data is installed in path lines now control underscore which is
00:27:09.600 the key bindings for undo is pressed when this happen we want to R
00:27:15.840 from a to a to do this one entry is popped from
00:27:21.840 the end pass lines and apply to Cent line destroing it if undo is press
00:27:27.880 repeat reply an empty string is popped returning to the stage before any
00:27:34.640 input this is how the the and functionary was implemented the pr
00:27:40.519 request can be found 7001 in the in depository so please check it uh if you
00:27:47.039 are interested let's take a quick look at the proart from earlier when controlcore
00:27:54.760 is pressed the key binding Cod and and function in the under function a previous St
00:28:01.760 taken from past line and apply to the current line the last ENT three is pass
00:28:07.799 line is removed when lendering is performed the previous state is
00:28:13.519 displayed completing the under operation successfully let's look at the
00:28:27.120 demo when you type if one 2 3 and Del
00:28:32.720 line to oh H pressing control
00:28:41.320 underscore H undo station destroing line two the under
00:28:48.080 also work correctly in the middle of an inut line and the Cal position returns
00:28:53.720 to where it during the operation with this we've successfully implement it and
00:29:10.000 thank to summarize line is a pure designed to be compatible with G line
00:29:16.799 and Li it for has line editing features and can be extended by L not that even
00:29:23.760 when requiring Le line X the line May sometimes be called if you have any
00:29:29.480 feature requests or bug reports please feel free to reach out on the Luby RI
00:29:37.080 repository and here are the links from the foot notes these are versions Ed for
00:29:42.279 testing in this presentation this concludes my presentation enjoy coding on the command
00:29:48.880 line with line thank you very much
Explore all talks recorded at RubyConf 2024
+64