Jump to content

Readline interface: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 20:
{{trans|D}}
 
<langsyntaxhighlight lang="11l">[String] histArr
 
F hello()
Line 53:
I line == ‘exit’
L.break
aa.get(line, help)()</langsyntaxhighlight>
 
=={{header|C}}==
A program that does absolutely nothing. Type 'help' for help.
<langsyntaxhighlight lang="c">#include <readline/readline.h>
#include <readline/history.h>
#include <string.h>
Line 81:
puts("Yes...?");
}
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
{{trans|D}}
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
Line 146:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{trans|D}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <string>
#include <vector>
Line 212:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight Dlang="d">module readline_interface;
 
import std.stdio;
Line 267:
write(">");
}
}</langsyntaxhighlight>
{{out}}
<pre>Enter a command, type help for a listing.
Line 288:
=={{header|Go}}==
{{trans|D}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 348:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 375:
=={{header|Java}}==
{{trans|C#}}
<langsyntaxhighlight lang="java">import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Line 433:
}
}
}</langsyntaxhighlight>
 
=={{header|Julia}}==
Line 440:
Simple program that does nothing (copy of [[#C | C]]).
 
<langsyntaxhighlight lang="julia">function input(prompt::AbstractString)
print(prompt)
r = readline(STDIN)
Line 455:
end
 
input("This is a common prompt> ")</langsyntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
var range = intArrayOf() // empty initially
Line 607:
println()
}
}</langsyntaxhighlight>
 
{{out}}
Line 689:
Nim provides a module <code>rdstdin</code> to read form standard input file. This modules provides navigation in history of previous commands using the up and down keys.
 
<langsyntaxhighlight Nimlang="nim">import rdstdin, strutils, tables
 
var history: seq[string]
Line 726:
echo "Unknown command, try again."
else:
Vfs[line]()</langsyntaxhighlight>
 
{{out}}
Line 750:
gp uses readline, but it can also be used directly in PARI:
 
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <pari/pari.h>
#include <readline/readline.h>
Line 794:
}
return 0;
}</langsyntaxhighlight>
 
<small>Code thanks to [http://pari.math.u-bordeaux.fr/archives/pari-dev-1002/msg00023.html Bill Allombert]</small>
Line 800:
=={{header|Perl}}==
A Perl shell with command history, line-editing and variable-name completion. Simplified from the example supplied with the CPAN module <code>Term::Readline::Gnu</code>.
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use Term::ReadLine;
Line 857:
}
return undef;
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 908:
watch.pike is the solution from [[Simple database#Pike]]. this solution demonstrates how to retrofit an application with a readline interface by inheriting the original and overriding specific functions.
 
<langsyntaxhighlight lang="pike">#!/usr/bin/pike
 
inherit "watch.pike";
Line 973:
}
}
}</langsyntaxhighlight>
 
Sample session:
Line 1,000:
=={{header|Python}}==
Python readline interface is enabled by default in the interpreter REPL, and can be enabled in user code simply by importing the readline module
<langsyntaxhighlight lang="python">#!/usr/bin/env python3
 
#
Line 1,014:
except:
break
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
Line 1,033:
<br>The HELP (or '''?'''), REDO, error checking, and abbreviations took up most of the program.
<br>"User" commands (subroutines) are identified with a leading period ('''.''') to make it easier to understand what's what.
<langsyntaxhighlight lang="rexx">/*REXX program implements a simple "readline" shell (modeled after a DOS shell). */
trace off /*suppress echoing of non-zero retCodes*/
signal on syntax; signal on noValue /*handle REXX program errors. */
Line 1,161:
end /*select*/
return ccc
</syntaxhighlight>
</lang>
This REXX program makes use of &nbsp; '''LINESIZE''' &nbsp; REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console).
<br>The &nbsp; '''LINESIZE.REX''' &nbsp; REXX program is included here &nbsp; ──► &nbsp; [[LINESIZE.REX]].<br>
Line 1,318:
<br>A history of the commands is navigated by the up- and down-keys. All commands are just echoed, except "quit" which exits.
<br>It uses the Ruby 2.3 method Hash#to_proc.
<langsyntaxhighlight lang="ruby">require "readline"
require "abbrev"
 
Line 1,327:
exit if buf.strip == "quit"
p buf
end</langsyntaxhighlight>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">require('Term::ReadLine')
 
var term = %O<Term::ReadLine>.new('Example')
Line 1,345:
 
say "You inserted <<#{cmd}>>"
}</langsyntaxhighlight>
 
=={{header|Wren}}==
{{trans|Go}}
<langsyntaxhighlight lang="ecmascript">import "io" for Stdin, Stdout
 
class ReadLine {
Line 1,397:
}
 
ReadLine.start</langsyntaxhighlight>
 
{{out}}
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.