1 |
|
2 |
|
3 |
|
4 |
|
5 | ############################################################################################################
|
6 | @constants = require './constants'
|
7 | @separator = ' '
|
8 | @depth_of_inspect = 20
|
9 | TYPES = require 'coffeenode-types'
|
10 | isa_text = TYPES.isa_text.bind TYPES
|
11 | _rpr = ( require 'util' ).inspect
|
12 |
|
13 | #-----------------------------------------------------------------------------------------------------------
|
14 | @rpr = ( x ) ->
|
15 | return _rpr x, depth: @depth_of_inspect
|
16 |
|
17 | #-----------------------------------------------------------------------------------------------------------
|
18 | @get_output_method = ( target, options ) ->
|
19 | R = ( P... ) =>
|
20 | last_idx = P.length - 1
|
21 | for p, idx in P
|
22 | target.write if isa_text p then p else @rpr p
|
23 | target.write @separator unless idx is last_idx
|
24 | target.write '\n'
|
25 | #.........................................................................................................
|
26 | return R
|
27 |
|
28 | #-----------------------------------------------------------------------------------------------------------
|
29 | @log = @get_output_method process.stderr
|
30 | @echo = @get_output_method process.stdout
|
31 |
|
32 | #-----------------------------------------------------------------------------------------------------------
|
33 | @clear_line_right = @constants.clear_line_right
|
34 | @clear_line_left = @constants.clear_line_left
|
35 | @clear_line = @constants.clear_line
|
36 | @clear_below = @constants.clear_below
|
37 | @clear_above = @constants.clear_above
|
38 | @clear = @constants.clear
|
39 |
|
40 | #-----------------------------------------------------------------------------------------------------------
|
41 | @goto = ( line_nr = 1, column_nr = 1 ) -> return "\x1b[#{line_nr};#{column_nr}H"
|
42 | @goto_column = ( column_nr = 1 ) -> return "\x1b[#{column_nr}G"
|
43 | #...........................................................................................................
|
44 | @up = ( count = 1 ) -> return "\x1b[#{count}A"
|
45 | @down = ( count = 1 ) -> return "\x1b[#{count}B"
|
46 | @right = ( count = 1 ) -> return "\x1b[#{count}C"
|
47 | @left = ( count = 1 ) -> return "\x1b[#{count}D"
|
48 | #...........................................................................................................
|
49 | @move = ( line_count, column_count ) ->
|
50 | return ( ( if line_count < 0 then @up line_count else @down line_count ) +
|
51 | ( if column_count < 0 then @left column_count else @right column_count ) )
|
52 |
|
53 | #-----------------------------------------------------------------------------------------------------------
|
54 | @ring_bell = ->
|
55 | process.stdout.write "\x07"
|
56 |
|
57 | #-----------------------------------------------------------------------------------------------------------
|
58 | effect_names =
|
59 | blink: 1
|
60 | bold: 1
|
61 | reverse: 1
|
62 | underline: 1
|
63 | #...........................................................................................................
|
64 | for effect_name of effect_names
|
65 | effect_on = @constants[ effect_name ]
|
66 | effect_off = @constants[ 'no_' + effect_name ]
|
67 | do ( effect_name, effect_on, effect_off ) =>
|
68 | @[ effect_name ] = ( P... ) =>
|
69 | R = [ effect_on, ]
|
70 | last_idx = P.length - 1
|
71 | for p, idx in P
|
72 | R.push if isa_text p then p else @rpr p
|
73 | if idx isnt last_idx
|
74 | R.push effect_on
|
75 | R.push @separator
|
76 | R.push effect_off
|
77 | return R.join ''
|
78 | #...........................................................................................................
|
79 | for color_name, color_code of @constants[ 'colors' ]
|
80 | do ( color_name, color_code ) =>
|
81 | @[ color_name ] = ( P... ) =>
|
82 | R = [ color_code, ]
|
83 | last_idx = P.length - 1
|
84 | for p, idx in P
|
85 | R.push if isa_text p then p else @rpr p
|
86 | if idx isnt last_idx
|
87 | R.push color_code
|
88 | R.push @separator
|
89 | R.push @constants[ 'reset' ]
|
90 | return R.join ''
|
91 |
|
92 | # #-----------------------------------------------------------------------------------------------------------
|
93 | # $.length_of_ansi_text = ( text ) ->
|
94 | # return ( text.replace /\x1b[^m]m/, '' ).length
|
95 |
|
96 | # #-----------------------------------------------------------------------------------------------------------
|
97 | # $.truth = ( P... ) ->
|
98 | # return ( ( ( if p == true then green else if p == false then red else white ) p ) for p in P ).join ''
|
99 |
|
100 | # #-----------------------------------------------------------------------------------------------------------
|
101 | # rainbow_colors = [ red, green, yellow, blue, magenta, cyan, orange, olive, plum, gold, ]
|
102 | # rainbow_idx = -1
|
103 |
|
104 | # #-----------------------------------------------------------------------------------------------------------
|
105 | # $.rainbow = ( P... ) ->
|
106 | # rainbow_idx += 1
|
107 | # rainbow_idx = 0 if rainbow_idx >= rainbow_colors.length
|
108 | # return rainbow_colors[ rainbow_idx ] P...
|
109 |
|
110 |
|