@@ -19,14 +19,15 @@ include("imshow.jl")
19
19
# overload default show in the REPL for colorant (arrays)
20
20
21
21
const colormode = TermColorDepth[TermColor256 ()]
22
+ const should_render_image = Bool[true ]
22
23
23
24
"""
24
25
use_256()
25
26
26
27
Triggers `imshow256` automatically if an array of colorants is to
27
28
be displayed in the julia REPL. (This is the default)
28
29
"""
29
- use_256 () = (colormode[1 ] = TermColor256 ())
30
+ use_256 () = (colormode[1 ] = TermColor256 (); should_render_image[ 1 ] = true )
30
31
31
32
"""
32
33
use_24bit()
@@ -35,28 +36,57 @@ Triggers `imshow24bit` automatically if an array of colorants is to
35
36
be displayed in the julia REPL.
36
37
Call `ImageInTerminal.use_256()` to restore default behaviour.
37
38
"""
38
- use_24bit () = (colormode[1 ] = TermColor24bit ())
39
+ use_24bit () = (colormode[1 ] = TermColor24bit (); should_render_image[1 ] = true )
40
+
41
+ """
42
+ disable_encoding()
43
+
44
+ Disable the image encoding feature and show images as if they are normal arrays.
45
+
46
+ This can be restored by calling `ImageInTerminal.enable_encoding()`.
47
+ """
48
+ disable_encoding () = (should_render_image[1 ] = false )
49
+
50
+ """
51
+ enable_encoding()
52
+
53
+ Enable the image encoding feature and show images in terminal.
54
+
55
+ This can be disabled by calling `ImageInTerminal.disable_encoding()`. To choose between
56
+ different encoding method, call `ImageInTerminal.use_256()` or `ImageInTerminal.use_24bit()`.
57
+ """
58
+ enable_encoding () = (should_render_image[1 ] = true )
59
+
39
60
40
61
# colorant arrays
41
62
function Base. show (
42
- io:: IO , :: MIME"text/plain" ,
63
+ io:: IO , mime :: MIME"text/plain" ,
43
64
img:: AbstractArray{<:Colorant} )
44
- println (io, summary (img), " :" )
45
- ImageInTerminal. imshow (io, img, colormode[1 ])
65
+ if should_render_image[1 ]
66
+ println (io, summary (img), " :" )
67
+ ImageInTerminal. imshow (io, img, colormode[1 ])
68
+ else
69
+ invoke (Base. show, Tuple{typeof (io), typeof (mime), AbstractArray}, io, mime, img)
70
+ end
46
71
end
47
72
48
73
# colorant
49
- function Base. show (io:: IO , :: MIME"text/plain" , color:: Colorant )
50
- fgcol = _colorant2ansi (color, colormode[1 ])
51
- chr = _charof (alpha (color))
52
- print (io, Crayon (foreground = fgcol), chr, chr, " " )
53
- print (io, Crayon (foreground = :white ), color)
54
- print (io, Crayon (reset = true ))
74
+ function Base. show (io:: IO , mime:: MIME"text/plain" , color:: Colorant )
75
+ if should_render_image[1 ]
76
+ fgcol = _colorant2ansi (color, colormode[1 ])
77
+ chr = _charof (alpha (color))
78
+ print (io, Crayon (foreground = fgcol), chr, chr, " " )
79
+ print (io, Crayon (foreground = :white ), color)
80
+ print (io, Crayon (reset = true ))
81
+ else
82
+ invoke (Base. show, Tuple{typeof (io), typeof (mime), Any}, io, mime, color)
83
+ end
55
84
end
56
85
57
86
function __init__ ()
58
87
# use 24bit if the terminal supports it
59
88
lowercase (get (ENV , " COLORTERM" , " " )) in (" 24bit" , " truecolor" ) && use_24bit ()
89
+ enable_encoding ()
60
90
end
61
91
62
92
end # module
0 commit comments