131 lines
26 KiB
HTML
131 lines
26 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Interacting With Julia · The Julia Language</title><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||
|
||
ga('create', 'UA-28835595-6', 'auto');
|
||
ga('send', 'pageview');
|
||
</script><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link href="../assets/documenter.css" rel="stylesheet" type="text/css"/><link href="../assets/julia-manual.css" rel="stylesheet" type="text/css"/></head><body><nav class="toc"><a href="../index.html"><img class="logo" src="../assets/logo.png" alt="The Julia Language logo"/></a><h1>The Julia Language</h1><select id="version-selector" onChange="window.location.href=this.value" style="visibility: hidden"></select><form class="search" id="search-form" action="../search.html"><input id="search-query" name="q" type="text" placeholder="Search docs"/></form><ul><li><a class="toctext" href="../index.html">Home</a></li><li><span class="toctext">Manual</span><ul><li><a class="toctext" href="introduction.html">Introduction</a></li><li><a class="toctext" href="getting-started.html">Getting Started</a></li><li><a class="toctext" href="variables.html">Variables</a></li><li><a class="toctext" href="integers-and-floating-point-numbers.html">Integers and Floating-Point Numbers</a></li><li><a class="toctext" href="mathematical-operations.html">Mathematical Operations and Elementary Functions</a></li><li><a class="toctext" href="complex-and-rational-numbers.html">Complex and Rational Numbers</a></li><li><a class="toctext" href="strings.html">Strings</a></li><li><a class="toctext" href="functions.html">Functions</a></li><li><a class="toctext" href="control-flow.html">Control Flow</a></li><li><a class="toctext" href="variables-and-scoping.html">Scope of Variables</a></li><li><a class="toctext" href="types.html">Types</a></li><li><a class="toctext" href="methods.html">Methods</a></li><li><a class="toctext" href="constructors.html">Constructors</a></li><li><a class="toctext" href="conversion-and-promotion.html">Conversion and Promotion</a></li><li><a class="toctext" href="interfaces.html">Interfaces</a></li><li><a class="toctext" href="modules.html">Modules</a></li><li><a class="toctext" href="documentation.html">Documentation</a></li><li><a class="toctext" href="metaprogramming.html">Metaprogramming</a></li><li><a class="toctext" href="arrays.html">Multi-dimensional Arrays</a></li><li><a class="toctext" href="linear-algebra.html">Linear algebra</a></li><li><a class="toctext" href="networking-and-streams.html">Networking and Streams</a></li><li><a class="toctext" href="parallel-computing.html">Parallel Computing</a></li><li><a class="toctext" href="dates.html">Date and DateTime</a></li><li class="current"><a class="toctext" href="interacting-with-julia.html">Interacting With Julia</a><ul class="internal"><li><a class="toctext" href="#The-different-prompt-modes-1">The different prompt modes</a></li><li><a class="toctext" href="#Key-bindings-1">Key bindings</a></li><li><a class="toctext" href="#Tab-completion-1">Tab completion</a></li><li><a class="toctext" href="#Customizing-Colors-1">Customizing Colors</a></li></ul></li><li><a class="toctext" href="running-external-programs.html">Running External Programs</a></li><li><a class="toctext" href="calling-c-and-fortran-code.html">Calling C and Fortran Code</a></li><li><a class="toctext" href="handling-operating-system-variation.html">Handling Operating System Variation</a></li><li><a class="toctext" href="environment-variables.html">Environment Variables</a></li><li><a class="toctext" href="embedding.html">Embedding Julia</a></li><li><a class="toctext" href="packages.html">Packages</a></li><li><a class="toctext" href="profile.html">Profiling</a></li><li><a class="toctext" href="stacktraces.html">Stack Traces</a></li><li><a class="toctext" href="performance-tips.html">Performance Tips</a></li><li><a class="toctext" href="workflow-tips.html">Workflow Tips</a></li><li><a class="toctext" href="style-guide.html">Style Guide</a></li><li><a class="toctext" href="faq.html">Frequently Asked Questions</a></li><li><a class="toctext" href="noteworthy-differences.html">Noteworthy Differences from other Languages</a></li><li><a class="toctext" href="unicode-input.html">Unicode Input</a></li></ul></li><li><span class="toctext">Standard Library</span><ul><li><a class="toctext" href="../stdlib/base.html">Essentials</a></li><li><a class="toctext" href="../stdlib/collections.html">Collections and Data Structures</a></li><li><a class="toctext" href="../stdlib/math.html">Mathematics</a></li><li><a class="toctext" href="../stdlib/numbers.html">Numbers</a></li><li><a class="toctext" href="../stdlib/strings.html">Strings</a></li><li><a class="toctext" href="../stdlib/arrays.html">Arrays</a></li><li><a class="toctext" href="../stdlib/parallel.html">Tasks and Parallel Computing</a></li><li><a class="toctext" href="../stdlib/linalg.html">Linear Algebra</a></li><li><a class="toctext" href="../stdlib/constants.html">Constants</a></li><li><a class="toctext" href="../stdlib/file.html">Filesystem</a></li><li><a class="toctext" href="../stdlib/io-network.html">I/O and Network</a></li><li><a class="toctext" href="../stdlib/punctuation.html">Punctuation</a></li><li><a class="toctext" href="../stdlib/sort.html">Sorting and Related Functions</a></li><li><a class="toctext" href="../stdlib/pkg.html">Package Manager Functions</a></li><li><a class="toctext" href="../stdlib/dates.html">Dates and Time</a></li><li><a class="toctext" href="../stdlib/iterators.html">Iteration utilities</a></li><li><a class="toctext" href="../stdlib/test.html">Unit Testing</a></li><li><a class="toctext" href="../stdlib/c.html">C Interface</a></li><li><a class="toctext" href="../stdlib/libc.html">C Standard Library</a></li><li><a class="toctext" href="../stdlib/libdl.html">Dynamic Linker</a></li><li><a class="toctext" href="../stdlib/profile.html">Profiling</a></li><li><a class="toctext" href="../stdlib/stacktraces.html">StackTraces</a></li><li><a class="toctext" href="../stdlib/simd-types.html">SIMD Support</a></li></ul></li><li><span class="toctext">Developer Documentation</span><ul><li><a class="toctext" href="../devdocs/reflection.html">Reflection and introspection</a></li><li><span class="toctext">Documentation of Julia's Internals</span><ul><li><a class="toctext" href="../devdocs/init.html">Initialization of the Julia runtime</a></li><li><a class="toctext" href="../devdocs/ast.html">Julia ASTs</a></li><li><a class="toctext" href="../devdocs/types.html">More about types</a></li><li><a class="toctext" href="../devdocs/object.html">Memory layout of Julia Objects</a></li><li><a class="toctext" href="../devdocs/eval.html">Eval of Julia code</a></li><li><a class="toctext" href="../devdocs/callconv.html">Calling Conventions</a></li><li><a class="toctext" href="../devdocs/compiler.html">High-level Overview of the Native-Code Generation Process</a></li><li><a class="toctext" href="../devdocs/functions.html">Julia Functions</a></li><li><a class="toctext" href="../devdocs/cartesian.html">Base.Cartesian</a></li><li><a class="toctext" href="../devdocs/meta.html">Talking to the compiler (the <code>:meta</code> mechanism)</a></li><li><a class="toctext" href="../devdocs/subarrays.html">SubArrays</a></li><li><a class="toctext" href="../devdocs/sysimg.html">System Image Building</a></li><li><a class="toctext" href="../devdocs/llvm.html">Working with LLVM</a></li><li><a class="toctext" href="../devdocs/stdio.html">printf() and stdio in the Julia runtime</a></li><li><a class="toctext" href="../devdocs/boundscheck.html">Bounds checking</a></li><li><a class="toctext" href="../devdocs/locks.html">Proper maintenance and care of multi-threading locks</a></li><li><a class="toctext" href="../devdocs/offset-arrays.html">Arrays with custom indices</a></li><li><a class="toctext" href="../devdocs/libgit2.html">Base.LibGit2</a></li><li><a class="toctext" href="../devdocs/require.html">Module loading</a></li></ul></li><li><span class="toctext">Developing/debugging Julia's C code</span><ul><li><a class="toctext" href="../devdocs/backtraces.html">Reporting and analyzing crashes (segfaults)</a></li><li><a class="toctext" href="../devdocs/debuggingtips.html">gdb debugging tips</a></li><li><a class="toctext" href="../devdocs/valgrind.html">Using Valgrind with Julia</a></li><li><a class="toctext" href="../devdocs/sanitizers.html">Sanitizer support</a></li></ul></li></ul></li></ul></nav><article id="docs"><header><nav><ul><li>Manual</li><li><a href="interacting-with-julia.html">Interacting With Julia</a></li></ul><a class="edit-page" href="https://github.com/JuliaLang/julia/blob/master/doc/src/manual/interacting-with-julia.md"><span class="fa"></span> Edit on GitHub</a></nav><hr/><div id="topbar"><span>Interacting With Julia</span><a class="fa fa-bars" href="#"></a></div></header><h1><a class="nav-anchor" id="Interacting-With-Julia-1" href="#Interacting-With-Julia-1">Interacting With Julia</a></h1><p>Julia comes with a full-featured interactive command-line REPL (read-eval-print loop) built into the <code>julia</code> executable. In addition to allowing quick and easy evaluation of Julia statements, it has a searchable history, tab-completion, many helpful keybindings, and dedicated help and shell modes. The REPL can be started by simply calling <code>julia</code> with no arguments or double-clicking on the executable:</p><pre><code class="language-none">$ julia
|
||
_
|
||
_ _ _(_)_ | A fresh approach to technical computing
|
||
(_) | (_) (_) | Documentation: https://docs.julialang.org
|
||
_ _ _| |_ __ _ | Type "?help" for help.
|
||
| | | | | | |/ _` | |
|
||
| | |_| | | | (_| | | Version 0.6.0-dev.2493 (2017-01-31 18:53 UTC)
|
||
_/ |\__'_|_|_|\__'_| | Commit c99e12c* (0 days old master)
|
||
|__/ | x86_64-linux-gnu
|
||
|
||
julia></code></pre><p>To exit the interactive session, type <code>^D</code> – the control key together with the <code>d</code> key on a blank line – or type <code>quit()</code> followed by the return or enter key. The REPL greets you with a banner and a <code>julia></code> prompt.</p><h2><a class="nav-anchor" id="The-different-prompt-modes-1" href="#The-different-prompt-modes-1">The different prompt modes</a></h2><h3><a class="nav-anchor" id="The-Julian-mode-1" href="#The-Julian-mode-1">The Julian mode</a></h3><p>The REPL has four main modes of operation. The first and most common is the Julian prompt. It is the default mode of operation; each new line initially starts with <code>julia></code>. It is here that you can enter Julia expressions. Hitting return or enter after a complete expression has been entered will evaluate the entry and show the result of the last expression.</p><pre><code class="language-julia-repl">julia> string(1 + 2)
|
||
"3"</code></pre><p>There are a number useful features unique to interactive work. In addition to showing the result, the REPL also binds the result to the variable <code>ans</code>. A trailing semicolon on the line can be used as a flag to suppress showing the result.</p><pre><code class="language-julia-repl">julia> string(3 * 4);
|
||
|
||
julia> ans
|
||
"12"</code></pre><p>In Julia mode, the REPL supports something called <em>prompt pasting</em>. This activates when pasting text that starts with <code>julia> </code> into the REPL. In that case, only expressions starting with <code>julia> </code> are parsed, others are removed. This makes it is possible to paste a chunk of code that has been copied from a REPL session without having to scrub away prompts and outputs. This feature is enabled by default but can be disabled or enabled at will with <code>Base.REPL.enable_promptpaste(::Bool)</code>. If it is enabled, you can try it out by pasting the code block above this paragraph straight into the REPL. This feature does not work on the standard Windows command prompt due to its limitation at detecting when a paste occurs.</p><h3><a class="nav-anchor" id="Help-mode-1" href="#Help-mode-1">Help mode</a></h3><p>When the cursor is at the beginning of the line, the prompt can be changed to a help mode by typing <code>?</code>. Julia will attempt to print help or documentation for anything entered in help mode:</p><pre><code class="language-julia-repl">julia> ? # upon typing ?, the prompt changes (in place) to: help?>
|
||
|
||
help?> string
|
||
search: string String stringmime Cstring Cwstring RevString readstring randstring bytestring SubString
|
||
|
||
string(xs...)
|
||
|
||
Create a string from any values using the print function.</code></pre><p>Macros, types and variables can also be queried:</p><pre><code class="language-none">help?> @time
|
||
@time
|
||
|
||
A macro to execute an expression, printing the time it took to execute, the number of allocations,
|
||
and the total number of bytes its execution caused to be allocated, before returning the value of the
|
||
expression.
|
||
|
||
See also @timev, @timed, @elapsed, and @allocated.
|
||
|
||
help?> AbstractString
|
||
search: AbstractString AbstractSparseMatrix AbstractSparseVector AbstractSet
|
||
|
||
No documentation found.
|
||
|
||
Summary:
|
||
|
||
abstract AbstractString <: Any
|
||
|
||
Subtypes:
|
||
|
||
Base.Test.GenericString
|
||
DirectIndexString
|
||
String</code></pre><p>Help mode can be exited by pressing backspace at the beginning of the line.</p><h3><a class="nav-anchor" id="man-shell-mode-1" href="#man-shell-mode-1">Shell mode</a></h3><p>Just as help mode is useful for quick access to documentation, another common task is to use the system shell to execute system commands. Just as <code>?</code> entered help mode when at the beginning of the line, a semicolon (<code>;</code>) will enter the shell mode. And it can be exited by pressing backspace at the beginning of the line.</p><pre><code class="language-julia-repl">julia> ; # upon typing ;, the prompt changes (in place) to: shell>
|
||
|
||
shell> echo hello
|
||
hello</code></pre><h3><a class="nav-anchor" id="Search-modes-1" href="#Search-modes-1">Search modes</a></h3><p>In all of the above modes, the executed lines get saved to a history file, which can be searched. To initiate an incremental search through the previous history, type <code>^R</code> – the control key together with the <code>r</code> key. The prompt will change to <code>(reverse-i-search)`':</code>, and as you type the search query will appear in the quotes. The most recent result that matches the query will dynamically update to the right of the colon as more is typed. To find an older result using the same query, simply type <code>^R</code> again.</p><p>Just as <code>^R</code> is a reverse search, <code>^S</code> is a forward search, with the prompt <code>(i-search)`':</code>. The two may be used in conjunction with each other to move through the previous or next matching results, respectively.</p><h2><a class="nav-anchor" id="Key-bindings-1" href="#Key-bindings-1">Key bindings</a></h2><p>The Julia REPL makes great use of key bindings. Several control-key bindings were already introduced above (<code>^D</code> to exit, <code>^R</code> and <code>^S</code> for searching), but there are many more. In addition to the control-key, there are also meta-key bindings. These vary more by platform, but most terminals default to using alt- or option- held down with a key to send the meta-key (or can be configured to do so).</p><table><tr><th>Keybinding</th><th>Description</th></tr><tr><td><strong>Program control</strong></td><td> </td></tr><tr><td><code>^D</code></td><td>Exit (when buffer is empty)</td></tr><tr><td><code>^C</code></td><td>Interrupt or cancel</td></tr><tr><td><code>^L</code></td><td>Clear console screen</td></tr><tr><td>Return/Enter, <code>^J</code></td><td>New line, executing if it is complete</td></tr><tr><td>meta-Return/Enter</td><td>Insert new line without executing it</td></tr><tr><td><code>?</code> or <code>;</code></td><td>Enter help or shell mode (when at start of a line)</td></tr><tr><td><code>^R</code>, <code>^S</code></td><td>Incremental history search, described above</td></tr><tr><td><strong>Cursor movement</strong></td><td> </td></tr><tr><td>Right arrow, <code>^F</code></td><td>Move right one character</td></tr><tr><td>Left arrow, <code>^B</code></td><td>Move left one character</td></tr><tr><td>Home, <code>^A</code></td><td>Move to beginning of line</td></tr><tr><td>End, <code>^E</code></td><td>Move to end of line</td></tr><tr><td><code>^P</code></td><td>Change to the previous or next history entry</td></tr><tr><td><code>^N</code></td><td>Change to the next history entry</td></tr><tr><td>Up arrow</td><td>Move up one line (or to the previous history entry)</td></tr><tr><td>Down arrow</td><td>Move down one line (or to the next history entry)</td></tr><tr><td>Page-up</td><td>Change to the previous history entry that matches the text before the cursor</td></tr><tr><td>Page-down</td><td>Change to the next history entry that matches the text before the cursor</td></tr><tr><td><code>meta-F</code></td><td>Move right one word</td></tr><tr><td><code>meta-B</code></td><td>Move left one word</td></tr><tr><td><strong>Editing</strong></td><td> </td></tr><tr><td>Backspace, <code>^H</code></td><td>Delete the previous character</td></tr><tr><td>Delete, <code>^D</code></td><td>Forward delete one character (when buffer has text)</td></tr><tr><td>meta-Backspace</td><td>Delete the previous word</td></tr><tr><td><code>meta-D</code></td><td>Forward delete the next word</td></tr><tr><td><code>^W</code></td><td>Delete previous text up to the nearest whitespace</td></tr><tr><td><code>^K</code></td><td>"Kill" to end of line, placing the text in a buffer</td></tr><tr><td><code>^Y</code></td><td>"Yank" insert the text from the kill buffer</td></tr><tr><td><code>^T</code></td><td>Transpose the characters about the cursor</td></tr><tr><td><code>^Q</code></td><td>Write a number in REPL and press <code>^Q</code> to open editor at corresponding stackframe</td></tr></table><h3><a class="nav-anchor" id="Customizing-keybindings-1" href="#Customizing-keybindings-1">Customizing keybindings</a></h3><p>Julia's REPL keybindings may be fully customized to a user's preferences by passing a dictionary to <code>REPL.setup_interface()</code>. The keys of this dictionary may be characters or strings. The key <code>'*'</code> refers to the default action. Control plus character <code>x</code> bindings are indicated with <code>"^x"</code>. Meta plus <code>x</code> can be written <code>"\\Mx"</code>. The values of the custom keymap must be <code>nothing</code> (indicating that the input should be ignored) or functions that accept the signature <code>(PromptState, AbstractREPL, Char)</code>. The <code>REPL.setup_interface()</code> function must be called before the REPL is initialized, by registering the operation with <code>atreplinit()</code>. For example, to bind the up and down arrow keys to move through history without prefix search, one could put the following code in <code>.juliarc.jl</code>:</p><pre><code class="language-julia">import Base: LineEdit, REPL
|
||
|
||
const mykeys = Dict{Any,Any}(
|
||
# Up Arrow
|
||
"\e[A" => (s,o...)->(LineEdit.edit_move_up(s) || LineEdit.history_prev(s, LineEdit.mode(s).hist)),
|
||
# Down Arrow
|
||
"\e[B" => (s,o...)->(LineEdit.edit_move_up(s) || LineEdit.history_next(s, LineEdit.mode(s).hist))
|
||
)
|
||
|
||
function customize_keys(repl)
|
||
repl.interface = REPL.setup_interface(repl; extra_repl_keymap = mykeys)
|
||
end
|
||
|
||
atreplinit(customize_keys)</code></pre><p>Users should refer to <code>base/LineEdit.jl</code> to discover the available actions on key input.</p><h2><a class="nav-anchor" id="Tab-completion-1" href="#Tab-completion-1">Tab completion</a></h2><p>In both the Julian and help modes of the REPL, one can enter the first few characters of a function or type and then press the tab key to get a list all matches:</p><pre><code class="language-julia-repl">julia> stri[TAB]
|
||
stride strides string stringmime strip
|
||
|
||
julia> Stri[TAB]
|
||
StridedArray StridedMatrix StridedVecOrMat StridedVector String</code></pre><p>The tab key can also be used to substitute LaTeX math symbols with their Unicode equivalents, and get a list of LaTeX matches as well:</p><pre><code class="language-julia-repl">julia> \pi[TAB]
|
||
julia> π
|
||
π = 3.1415926535897...
|
||
|
||
julia> e\_1[TAB] = [1,0]
|
||
julia> e₁ = [1,0]
|
||
2-element Array{Int64,1}:
|
||
1
|
||
0
|
||
|
||
julia> e\^1[TAB] = [1 0]
|
||
julia> e¹ = [1 0]
|
||
1×2 Array{Int64,2}:
|
||
1 0
|
||
|
||
julia> \sqrt[TAB]2 # √ is equivalent to the sqrt() function
|
||
julia> √2
|
||
1.4142135623730951
|
||
|
||
julia> \hbar[TAB](h) = h / 2\pi[TAB]
|
||
julia> ħ(h) = h / 2π
|
||
ħ (generic function with 1 method)
|
||
|
||
julia> \h[TAB]
|
||
\hat \hermitconjmatrix \hkswarow \hrectangle
|
||
\hatapprox \hexagon \hookleftarrow \hrectangleblack
|
||
\hbar \hexagonblack \hookrightarrow \hslash
|
||
\heartsuit \hksearow \house \hspace
|
||
|
||
julia> α="\alpha[TAB]" # LaTeX completion also works in strings
|
||
julia> α="α"</code></pre><p>A full list of tab-completions can be found in the <a href="unicode-input.html#Unicode-Input-1">Unicode Input</a> section of the manual.</p><p>Completion of paths works for strings and julia's shell mode:</p><pre><code class="language-julia-repl">julia> path="/[TAB]"
|
||
.dockerenv .juliabox/ boot/ etc/ lib/ media/ opt/ root/ sbin/ sys/ usr/
|
||
.dockerinit bin/ dev/ home/ lib64/ mnt/ proc/ run/ srv/ tmp/ var/
|
||
shell> /[TAB]
|
||
.dockerenv .juliabox/ boot/ etc/ lib/ media/ opt/ root/ sbin/ sys/ usr/
|
||
.dockerinit bin/ dev/ home/ lib64/ mnt/ proc/ run/ srv/ tmp/ var/</code></pre><p>Tab completion can help with investigation of the available methods matching the input arguments:</p><pre><code class="language-julia-repl">julia> max([TAB] # All methods are displayed, not shown here due to size of the list
|
||
|
||
julia> max([1, 2], [TAB] # All methods where `Vector{Int}` matches as first argument
|
||
max(x, y) in Base at operators.jl:215
|
||
max(a, b, c, xs...) in Base at operators.jl:281
|
||
|
||
julia> max([1, 2], max(1, 2), [TAB] # All methods matching the arguments.
|
||
max(x, y) in Base at operators.jl:215
|
||
max(a, b, c, xs...) in Base at operators.jl:281</code></pre><p>Keywords are also displayed in the suggested methods, see second line after <code>;</code> where <code>limit</code> and <code>keep</code> are keyword arguments:</p><pre><code class="language-julia-repl">julia> split("1 1 1", [TAB]
|
||
split(str::AbstractString) in Base at strings/util.jl:278
|
||
split{T<:AbstractString}(str::T, splitter; limit, keep) in Base at strings/util.jl:254</code></pre><p>The completion of the methods uses type inference and can therefore see if the arguments match even if the arguments are output from functions. The function needs to be type stable for the completion to be able to remove non-matching methods.</p><p>Tab completion can also help completing fields:</p><pre><code class="language-julia-repl">julia> Pkg.a[TAB]
|
||
add available</code></pre><p>Fields for output from functions can also be completed:</p><pre><code class="language-julia-repl">julia> split("","")[1].[TAB]
|
||
endof offset string</code></pre><p>The completion of fields for output from functions uses type inference, and it can only suggest fields if the function is type stable.</p><h2><a class="nav-anchor" id="Customizing-Colors-1" href="#Customizing-Colors-1">Customizing Colors</a></h2><p>The colors used by Julia and the REPL can be customized, as well. To change the color of the Julia prompt you can add something like the following to your <code>.juliarc.jl</code> file, which is to be placed inside your home directory:</p><pre><code class="language-julia">function customize_colors(repl)
|
||
repl.prompt_color = Base.text_colors[:cyan]
|
||
end
|
||
|
||
atreplinit(customize_colors)</code></pre><p>The available color keys can be seen by typing <code>Base.text_colors</code> in the help mode of the REPL. In addition, the integers 0 to 255 can be used as color keys for terminals with 256 color support.</p><p>You can also change the colors for the help and shell prompts and input and answer text by setting the appropriate field of <code>repl</code> in the <code>customize_colors</code> function above (respectively, <code>help_color</code>, <code>shell_color</code>, <code>input_color</code>, and <code>answer_color</code>). For the latter two, be sure that the <code>envcolors</code> field is also set to false.</p><p>It is also possible to apply boldface formatting by using <code>Base.text_colors[:bold]</code> as a color. For instance, to print answers in boldface font, one can use the following as a <code>.juliarc.jl</code>:</p><pre><code class="language-julia">function customize_colors(repl)
|
||
repl.envcolors = false
|
||
repl.answer_color = Base.text_colors[:bold]
|
||
end
|
||
|
||
atreplinit(customize_colors)</code></pre><p>You can also customize the color used to render warning and informational messages by setting the appropriate environment variables. For instance, to render error, warning, and informational messages respectively in magenta, yellow, and cyan you can add the following to your <code>.juliarc.jl</code> file:</p><pre><code class="language-julia">ENV["JULIA_ERROR_COLOR"] = :magenta
|
||
ENV["JULIA_WARN_COLOR"] = :yellow
|
||
ENV["JULIA_INFO_COLOR"] = :cyan</code></pre><footer><hr/><a class="previous" href="dates.html"><span class="direction">Previous</span><span class="title">Date and DateTime</span></a><a class="next" href="running-external-programs.html"><span class="direction">Next</span><span class="title">Running External Programs</span></a></footer></article></body></html>
|