Branch: Tag:

2022-07-25

2022-07-25 08:34:21 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Documentation [Readline]: Added an example of how to use.

2097:   <dt class='head--doc'>Description</dt>   <dd class='body--doc'><p>Terminfo database for a single directory.</p>   </dd></dl></dd></dl></dd></dl><dl><dt><h2 class='header'>Class <b class='ms datatype'>Stdio.Readline</b></h2> - </dt><dd> + </dt><dd><dl class='group--doc'> + <dt class='head--doc'>Description</dt> + <dd class='body--doc'><p>Terminal-aware line-based input.</p> + </dd> + <dt class='head--doc'>Example</dt> + <dd class='example'><pre><p>// Get a Readline object connected to Stdio.stdin/Stdio.stdout. +  Stdio.Readline readline = Stdio.Readline();</p> + <p> // Enable history. +  string|zero history_dump = Stdio.read_file(history_file); +  if (history_dump) { +  readline-&gt;enable_history(history_dump/"\n"); +  } else { +  readline-&gt;enable_history(512); // 512 lines of history. +  }</p> + <p> // Add a completion handler. +  readline-&gt;get_input_controller()-&gt;bind("\t", handle_completions);</p> + <p> // Output some message. +  readline-&gt;message("Welcome to some application.\n");</p> + <p> // Set a prompt. +  readline-&gt;set_prompt("&gt; ");</p> + <p> // Read some input. +  string command = readline-&gt;read();</p> + <p> // Save the history. +  Stdio.write_file(history_file, readline-&gt;get_history()-&gt;encode());</p> + </pre></dd> + <dt class='head--doc'>See also</dt> + <dd class='body--doc'><p><code>enable_history()</code>, <code>get_history()</code>, <code>get_input_controller()</code>, +  <code>message()</code>, <code>read()</code>, <code>set_prompt()</code></p> + </dd></dl>      <hr />   <dl class='group--doc'>