Skip to content

Instantly share code, notes, and snippets.

@aycabta
Last active September 14, 2021 13:26
Show Gist options
  • Save aycabta/6057f7edc7f8790c7d1ea38fb663a971 to your computer and use it in GitHub Desktop.
Save aycabta/6057f7edc7f8790c7d1ea38fb663a971 to your computer and use it in GitHub Desktop.

RubyKaigi 2021

Hello, everyone. My name is Itoyanagi. I'm a climber, in particular, I do a lot of sawanobori. It is said that "the best way to enjoy the mountains is Sawanobori," so I wade through rapids in the wilderness, climb waterfalls, sometimes procure food locally, sleep by the fire, and head for the headwaters.

I was supposed to give a technical presentation on the riverside, as I always do in my online presentations, but I couldn't make it at all. So, I just spliced together some random footage from some mountains, and overlaid a technical explanation on top of it.

First of all, let me explain what the schedule was like this time. When I was accepted to RubyKaigi, I hadn't implemented any of the accepted features. This is a rough technique called "Kaigi Driven Development" that Ruby committers often use to make progress by taking advantage of the fact that they will have to implement the content to present it. The deadline for submitting videos for this year's English presentation was August 31st. I started working on it on August 17th. It was all too late.

Anyway, no, it's not "anyway" or anything, but let me belatedly introduce myself.

I'm

  • a RDoc maintainer
  • a Ruby committer
  • a member of Ruby core team
  • a member of Asakusa.rb
  • a clibmer

Please enjoy the background of today's video, which shows climbing some mountains.

In recent years, Ruby's IRB has undergone significant improvements. The multi-line editing feature is a clear example of this. The implementation of the new feature is based on Reline, a software I wrote from scratch. It achieves the madness of doing all the terminal control on its own.

According to Naruse-san, a Ruby committer, there are "three major addictions in programming".

  • operating system
  • programming language
  • terminal
  • text editor

Reline implements "terminal" and "text editor" out of these. It's hell on earth.

It needs too much work just to add just small new features, so I've already added about 150 commits, even though I just started working on it on August 17th.

So, what is the feature that I've implemented in Reline? It is the "dialog window." You may be familiar with it from the past if you are using an IDE.

I'll show you a demonstration of the implementation in action here.

Since IRB is a "text editor for typing code," the dialog window is displayed at a location relative to the cursor position, just like IDE. You can also specify a relative distance to display it a little farther away.

DEMO

It is also possible to trap the specified keystrokes while a dialog window is displayed. The specified key doesn't enter into the normal keystroke processing of Reline, but can be handled by the dialog window callback. It's also possible to select and display a specific line in the dialog window. By combining these functions, it's possible to navigate through the dialog window using keystrokes.

DEMO

The width and height of the dialog window will be determined automatically, but you can also specify a maximum size. The width will be shortened by cutting down the amount of popping out, but the height will be scrolled.

DEMO

A scroll bar can also be displayed if necessary.

DEMO

You can also use an existing completion engine to achieve autocompletion without any special implementation on your own. I'll try it with just this code.

require 'reline'

Reline.autocompletion = true Reline.completion_proc = lambda { |target| completion_candidate = %w{rabbit rack rail ruby ...} completion_candidate.select { |item| item.start_with?(target) } } Reline.readmultiline('prompt> ') { |input| input.include?("\n") }

DEMO

Now then, let's take a look at a real-world example from the IRB.

Nowadays, IRB has completion turned on by default, so just add Reline.autocompletion = true and autocompletion will be displayed. Now you can use the rails console without worrying about adding many classes and methods to your business code.

DEMO

Here's the thing. Everything I've shown you so far is just preparation.

The already released stable version of IRB, which doesn't yet have the features introduced today, has a document viewing feature. After the usual tab key completion, pressing the tab key again with an "perfect match" will display the document.

DEMO

However, I find it difficult to notice this UI. In this form, it's just a "hidden command".

So, in the new IRB, we have implemented a document display along with autocomplete. Please see here.

DEMO

The best UI is one that requires no explanation. Accessing a document no longer requires an explanation. However, there is one explanation that I can't help to display. It's this one. "Press Alt+d to read the full document"

Press Alt+d as in the explanation. A key trap has been set to display the full document. "q" to exit the document view, and you will be back to the original screen.

DEMO

All of the major improvements to the IRB over the past few years have been resistance as the RDoc maintainer to the long-standing trend of not installing RDoc documentation to the local machines.

I need someone to help me maintain Reline.

RDoc and Reline are two of the largest standard attachment libraries written in Ruby. There should be almost no one in the world who can maintain them at all, but this depends less on being competent and more on demonstrating an unusual obsession with a very specialized area.

We'll only make each other unhappy if someone half-hearted comes along, but if someone really wants to work on it, I'd appreciate it. I think there are probably a few people like that in the world.

Alternatively, I look forward to your support via GitHub Sponsors.

https://github.com/sponsors/aycabta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment