diff --git a/REQUIRE b/REQUIRE index 548c914..ed6ec66 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,8 +1,9 @@ Lint 0.1.60 -julia 0.3.11 +julia 0.6 Compat 0.1 Formatting 0.1.2 DataArrays DataFrames DataFramesMeta Lazy +Missings diff --git a/src/TermWin.jl b/src/TermWin.jl index 32283b0..e2b546c 100644 --- a/src/TermWin.jl +++ b/src/TermWin.jl @@ -22,6 +22,7 @@ end using DataArrays using DataFrames using DataFramesMeta +using Missings macro lintpragma( s ) end @@ -120,17 +121,21 @@ function initsession() throw( "terminal doesn't support colors") end mousemask( BUTTON1_PRESSED | REPORT_MOUSE_POSITION ) - acs_map_ptr = cglobal( Libdl.dlsym( libncurses, :acs_map), UInt32 ) - acs_map_arr = pointer_to_array( acs_map_ptr, 128) + if is_apple() + acs_map_ptr = cglobal( Libdl.dlsym( libncurses, :acs_map), UInt32 ) + else + acs_map_ptr = cglobal( Libdl.dlsym( libncurses, :acs_map), UInt64 ) + end + acs_map_arr = unsafe_wrap(Array, acs_map_ptr, 128) start_color() # figure out how many colors are supported colorsptr = cglobal( Libdl.dlsym( libncurses, :COLORS), Int16 ) - colorsarr = pointer_to_array( colorsptr, 1 ) + colorsarr = unsafe_wrap(Array, colorsptr, 1 ) COLORS = colorsarr[1] colorsptr = cglobal( Libdl.dlsym( libncurses, :COLOR_PAIRS), Int16 ) - colorsarr = pointer_to_array( colorsptr, 1 ) + colorsarr = unsafe_wrap(Array, colorsptr, 1 ) COLOR_PAIRS = colorsarr[1] init_pair( 1, COLOR_RED, COLOR_BLACK ) @@ -342,9 +347,9 @@ end function titleof( x::Any ) typx = typeof( x ) if typx == Module || typx == Function - return utf8( string( x ) ) + return string( x ) else - return utf8( string( typx ) ) + return string( typx ) end end @@ -387,7 +392,7 @@ function tshow( x; kwargs... ) catch err bt = catch_backtrace() msg = wordwrap( string(err) * "\n" * string( bt ), 80 ) - widget = tshow_( msg; title=utf8("Error") ) + widget = tshow_( msg; title="Error" ) end if widget != nothing refresh( rootTwScreen ) @@ -459,7 +464,7 @@ function testkeydialog() win = winnewcenter( 6, width ) panel = new_panel( win ) box( win, 0, 0 ) - title = utf8( "Test Key/Mouse/Unicode" ) + title = "Test Key/Mouse/Unicode" keyhint = "[Esc to continue]" mvwprintw( win, 0, (@compat Int( (width-length(title))>>1)), "%s", title ) diff --git a/src/ccall.jl b/src/ccall.jl index e1dff57..eef50e2 100644 --- a/src/ccall.jl +++ b/src/ccall.jl @@ -7,14 +7,14 @@ function initscr() global libncurses, libpanel if libncurses == false try - libncurses = Libdl.dlopen("libncurses") - catch libncurses = Libdl.dlopen("libncursesw") + catch + libncurses = Libdl.dlopen("libncurses") end try - libpanel = Libdl.dlopen("libpanel") - catch libpanel = Libdl.dlopen("libpanelw") + catch + libpanel = Libdl.dlopen("libpanel") end end ccall( Libdl.dlsym( libncurses, :initscr), Ptr{Void}, () ) @@ -66,14 +66,14 @@ function mvwaddch( w::TwWindow, y::Int, x::Int, c ) end end -function mvwprintw{T<:AbstractString}( win::Ptr{Void}, row::Int, height::Int, fmt::ASCIIString, str::T ) +function mvwprintw{T<:AbstractString}( win::Ptr{Void}, row::Int, height::Int, fmt::String, str::T ) ccall( Libdl.dlsym( libncurses, :mvwprintw), Void, ( Ptr{Void}, Int, Int, Cstring, Cstring ), win, row, height, fmt, str ) end # note that it could in turn call another TwWindow... -function mvwprintw{T<:AbstractString}( w::TwWindow, y::Int, x::Int, fmt::ASCIIString, s::T ) +function mvwprintw{T<:AbstractString}( w::TwWindow, y::Int, x::Int, fmt::String, s::T ) if objtype( w.parent.value ) == :List && typeof( w.parent.value.window ) != TwWindow # terminal layer. use its pad mvwprintw( w.parent.value.data.pad, y+w.yloc, x+w.xloc, fmt, s ) @@ -322,7 +322,7 @@ function has_mouse() end function mousemask( mask ) - oldmm = Array( UInt64, 1 ) + oldmm = Array{UInt64}(1) resultmm = ccall( Libdl.dlsym( libncurses, :mousemask), UInt64, (UInt64, Ptr{UInt64}), mask, oldmm ) ( resultmm, oldmm[1]) end @@ -332,7 +332,7 @@ function mouseinterval( n::Int ) end #hack! -const mouseByteString = bytestring( Array( UInt8, 64 ) ) +mouseByteString = Vector{UInt8}(64) #unsafe_string( Array( UInt8, 64 ) ) function getmouse() #= type Mouse_Event_t diff --git a/src/dfutils.jl b/src/dfutils.jl index 42e53f8..a8153c1 100644 --- a/src/dfutils.jl +++ b/src/dfutils.jl @@ -22,14 +22,13 @@ defaultAggr( ::Type{} ) = :uniqvalue defaultAggr{T<:Real}( ::Type{T} ) = :sum defaultAggr{T}( ::Type{Array{T,1}} ) = :unionall -function liftAggrSpecToFunc( c::Symbol, dfa::UTF8String ) +function liftAggrSpecToFunc( c::Symbol, dfa::String ) if haskey( DataFrameAggrCache, (c, dfa ) ) return DataFrameAggrCache[ (c, dfa ) ] end ret = liftAggrSpecToFunc( c, parse( dfa ) ) DataFrameAggrCache[ (c, dfa) ] = ret end -liftAggrSpecToFunc( c::Symbol, dfa::ASCIIString ) = liftAggrSpecToFunc( c, utf8( dfa ) ) function liftAggrSpecToFunc( c::Symbol, dfa::Union{ Function, Symbol, Expr } ) if typeof( dfa ) == Function @@ -71,7 +70,7 @@ function liftAggrSpecToFunc( c::Symbol, dfa::Union{ Function, Symbol, Expr } ) convertExpression!( cdfa, c ) membernames = Dict{Union{Symbol,Expr}, Symbol}() - cdfa = DataFramesMeta.replace_syms(cdfa, membernames) + cdfa = DataFramesMeta.replace_syms!(cdfa, membernames) funargs = map(x -> :( getindex( _df_, $(x)) ), collect(keys(membernames))) funnameouter = gensym("DFAggr") funname = gensym() @@ -130,12 +129,20 @@ function uniqvalue( x::AbstractDataArray; skipna::Bool=true ) if length(l) == 1 return l[1] end - return NA + return missing end if length(lvls) == 1 return lvls[1] end - return NA + return missing +end + +function uniqvalue( x::Array ) + lvls = DataArrays.levels(x) + if length(lvls) == 1 + return lvls[1] + end + return missing end function uniqvalue{T<:AbstractString}( x::Union{ Array{T}, DataArray{T}, PooledDataArray{T} }; skipna::Bool=true, skipempty::Bool=true ) @@ -156,7 +163,7 @@ function uniqvalue{T<:AbstractString}( x::Union{ Array{T}, DataArray{T}, PooledD elseif length( l ) == 1 return l[1] end - return NA + return missing end if skipempty emptyidx = findfirst( lvls, "" ) @@ -172,16 +179,14 @@ function uniqvalue{T<:AbstractString}( x::Union{ Array{T}, DataArray{T}, PooledD elseif length( lvls ) == 1 return lvls[1] end - return NA + return missing end immutable CalcPivot spec::Expr by::Array{Symbol,1} - CalcPivot( x::UTF8String, by::Array{Symbol,1}=Symbol[] ) = CalcPivot( parse(x), by ) - CalcPivot( x::ASCIIString, by::Array{Symbol,1}=Symbol[] ) = CalcPivot( parse(utf8(x)), by ) - CalcPivot( x::UTF8String, by::Symbol ) = CalcPivot( parse(x), Symbol[ by ] ) - CalcPivot( x::ASCIIString, by::Symbol ) = CalcPivot( parse(utf8(x)), Symbol[ by ] ) + CalcPivot( x::String, by::Array{Symbol,1}=Symbol[] ) = CalcPivot( parse(x), by ) + CalcPivot( x::String, by::Symbol ) = CalcPivot( parse(x), Symbol[ by ] ) function CalcPivot( x::Expr, by::Symbol ) CalcPivot( x, Symbol[ by ] ) end @@ -238,7 +243,7 @@ function liftCalcPivotToFunc( ex::Expr, by::Array{Symbol,1} ) funname = gensym() membernames = Dict{Union{Symbol,Expr}, Symbol}() - cex = DataFramesMeta.replace_syms(cex, membernames) + cex = DataFramesMeta.replace_syms!(cex, membernames) # keys are the columns. values are the unique gensyms if !isempty( by ) # micro split-apply-combine @@ -253,7 +258,7 @@ function liftCalcPivotToFunc( ex::Expr, by::Array{Symbol,1} ) push!( aggr_args, Expr( :kw, a, Expr( :call, Expr( :ref, :aggrfuncs, QuoteNode( a ) ), lambdasym ) ) ) end - bycolsexpr=Expr( :vcat, map( _->QuoteNode(_), by )... ) # [ :a, :b, :c ... ] + bycolsexpr=Expr( :vcat, map( x->QuoteNode(x), by )... ) # [ :a, :b, :c ... ] aggrcode = Expr( :->, lambdasym, Expr( :call, DataFrame, aggr_args... ) ) code = :( function $funnameouter( _df_::AbstractDataFrame, c::Symbol; kwargs... ) # we need kwargs here for aggregate specs @@ -311,9 +316,9 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T}; mixedfraction=false,autoscale=:none,conversion="" ) n = length(breaks) - breakstrs = UTF8String[] - function formatter(_) - prefix * format( _*scale, + breakstrs = String[] + function formatter(x) + prefix * format( x*scale, precision=precision, commas=commas, stripzeros=stripzeros, @@ -332,12 +337,12 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T}; else ncategories = n end - pool = Array(UTF8String, ncategories ) + pool = Array(String, ncategories ) if rank rankwidth = length(string(ncategories)) end if !rank - rankprefixfunc = _->"" + rankprefixfunc = x->"" elseif reverse rankprefixfunc = j -> format( n+2-j, width=rankwidth ) * ranksep else @@ -347,7 +352,7 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T}; if S <: Integer && T <: Integer && scale == 1 # we use 1...5, 6, 7...10, 11+etc. if leftequal - breakminus1strs = UTF8String[] + breakminus1strs = String[] for b in breaks push!( breakminus1strs, formatter( b-1 ) ) end @@ -367,7 +372,7 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T}; pool[n+1+poolindexshift] = rankprefixfunc(n+1+poolindexshift)*breakstrs[n]*"+" end else - breakplus1strs = UTF8String[] + breakplus1strs = String[] for b in breaks push!( breakminus1strs, formatter( b+1 ) ) end @@ -391,13 +396,13 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T}; if leftequal brackL = "[" brackR = ")" - compareL = utf8( "<" ) + compareL = "<" compareR = "≥" else brackL = "(" brackR = "]" compareL = "≤" - compareR = utf8(">") + compareR = ">" end poolindexshift = -1 if boundedness in [ :unbounded, :boundedabove ] @@ -425,9 +430,9 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T}; end if leftequal compareL = " ≤ " - compareR = utf8(" < ") + compareR = " < " else - compareL = utf8(" < ") + compareL = " < " compareR = " ≤ " end poolindexshift = -1 @@ -458,7 +463,7 @@ end # bounded gives n-1 categories for n breaks. Values below min or above max will be NA function discretize{S<:Real, T<:Real}(x::AbstractArray{S,1}, breaks::Vector{T}; boundedness = :unbounded, - bucketstrs = UTF8String[], # if provided, all of below will be ignored. length must be length(breaks)+1 + bucketstrs = String[], # if provided, all of below will be ignored. length must be length(breaks)+1 leftequal=true, # t1 <= x < t2 or t1 < x <= t2? absolute=false, # t1 <= |x| < t2? rank=true, # add a rank to the string output for easier sorting? @@ -511,7 +516,7 @@ function discretize{S<:Real, T<:Real}(x::AbstractArray{S,1}, breaks::Vector{T}; if leftequal for i in 1:length(x) - if isna( x, i ) + if ismissing( x, i ) refs[i] = 0 elseif x2[i] < breaks[1] refs[i] = below_min_mult @@ -529,7 +534,7 @@ function discretize{S<:Real, T<:Real}(x::AbstractArray{S,1}, breaks::Vector{T}; end else for i in 1:length(x) - if isna( x, i ) + if ismissing( x, i ) refs[i] = 0 elseif x2[i] < breaks[1] refs[i] = below_min_mult @@ -579,7 +584,7 @@ end # use scale=100.0, suffix="%", to express the quantiles in percentages function discretize{S<:Real}(x::AbstractArray{S,1}; quantiles = Float64[], ngroups::Int = 4, kwargs ... ) if length( quantiles ) != 0 - if any( _ -> _ < 0.0 || _ > 1.0 , quantiles ) + if any( x -> x < 0.0 || x > 1.0 , quantiles ) error( "illegal quantile numbers outside [0,1]") end if !issorted(quantiles) @@ -629,12 +634,12 @@ function topnames{S<:AbstractString,T<:Real}( name::AbstractArray{S,1}, measure: nr = nrow( dfsorted ) if !absolute - pool = UTF8String[] + pool = String[] refs = fill(zero(DataArrays.DEFAULT_POOLED_REF_TYPE), nr ) lastval = zero( T ) lastrank = 0 for r in 1:nr - if isna( dfsorted[:measure], r ) + if ismissing( dfsorted[:measure], r ) continue else val = dfsorted[ r, :measure ] @@ -663,7 +668,7 @@ function topnames{S<:AbstractString,T<:Real}( name::AbstractArray{S,1}, measure: lastval = zero( T ) lastrank = 0 for r in 1:nr - if isna( dfsorted[:measure], r ) + if ismissing( dfsorted[:measure], r ) continue else val = dfsorted[ r, :measure ] @@ -684,12 +689,12 @@ function topnames{S<:AbstractString,T<:Real}( name::AbstractArray{S,1}, measure: end dfsorted[ :rankedflag ] = rankedflag dfsorted2 = sort( dfsorted, cols = [ :measure ], rev = [ true ] ) - rankstr = DataArray(UTF8String,nr) + rankstr = DataArray(String,nr) rankcount = 1 lastval = zero( T ) lastrank = 0 for r in 1:nr - if isna( dfsorted2[ :measure ], r ) + if ismissing( dfsorted2[ :measure ], r ) continue elseif dfsorted2[ r, :rankedflag ] val = dfsorted2[ r, :measure ] @@ -735,6 +740,6 @@ end import DataFrames.describe export describe -function describe{T}( io, dv::Array{T,1} ) +function describe{T}( io::IO, dv::Array{T,1} ) describe( io, DataArray( dv ) ) end diff --git a/src/format.jl b/src/format.jl index 5f30194..12cbeed 100644 --- a/src/format.jl +++ b/src/format.jl @@ -9,9 +9,9 @@ type FormatHints hidezero :: Bool alternative :: Bool mixedfraction :: Bool - suffix :: UTF8String + suffix :: String autoscale :: Symbol - conversion :: ASCIIString + conversion :: String end function FormatHints{T<:Integer}( ::Type{T} ) @@ -66,7 +66,7 @@ function applyformat{T<:AbstractString}( v::T, fmt::FormatHints ) end function applyformat( v::AbstractArray, fmt::FormatHints ) - strs = UTF8String[] + strs = String[] for s in v push!( strs, applyformat( s, fmt ) ) end diff --git a/src/precompile.jl b/src/precompile.jl index b9d9600..4e17d12 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -1,8 +1,8 @@ precompile( inject, (TwObj{TwTreeData}, Symbol ) ) -precompile( inject, (TwObj{TwTreeData}, ASCIIString ) ) +precompile( inject, (TwObj{TwTreeData}, String ) ) precompile( inject, (TwObj{TwDfTableData}, Symbol ) ) -precompile( inject, (TwObj{TwDfTableData}, ASCIIString ) ) +precompile( inject, (TwObj{TwDfTableData}, String ) ) precompile( inject, (TwObj{TwEntryData}, Symbol ) ) -precompile( inject, (TwObj{TwEntryData}, ASCIIString ) ) +precompile( inject, (TwObj{TwEntryData}, String ) ) precompile( inject, (TwObj{TwScreenData}, Symbol ) ) -precompile( inject, (TwObj{TwScreenData}, ASCIIString ) ) +precompile( inject, (TwObj{TwScreenData}, String ) ) diff --git a/src/readtoken.jl b/src/readtoken.jl index c17585d..dd3d2d7 100644 --- a/src/readtoken.jl +++ b/src/readtoken.jl @@ -1,4 +1,4 @@ -const keymap = Compat.@Dict( +const keymap = Dict( "\eOA" => :up, "\e[1;2A" => :shift_up, "\e[1;5A" => :ctrl_up, @@ -125,7 +125,7 @@ const keymap = Compat.@Dict( "\e"*string(@compat Char(0x152)) => :alt_pagedown ) -ncnummap = Compat.@Dict( +ncnummap = Dict( (@compat UInt(0x7f)) => :backspace, (@compat UInt(0x01)) => :ctrl_a, (@compat UInt(0x02)) => :ctrl_b, @@ -305,7 +305,7 @@ ncnummap = Compat.@Dict( ) -const keypadmap = Compat.@Dict( +const keypadmap = Dict( :keypad_dot => ".", :keypad_enter => Symbol( "return" ), :keypad_asterisk => "*", @@ -369,39 +369,39 @@ function readtoken( win::Ptr{Void} ) return string( @compat Char( c ) ) end elseif 192 <= c <= 223 # utf8 based logic starts here - bs = Array( UInt8, 2 ) + bs = Array{UInt8}( 2 ) bs[1] = @compat UInt8( c ) bs[2] = @compat UInt8( wgetch( win ) ) - return convert( UTF8String, bs ) + return convert( String, bs ) elseif 224 <= c <= 239 - bs = Array( UInt8, 3 ) + bs = Array{UInt8}( 3 ) bs[1] = @compat UInt8( c ) bs[2] = @compat UInt8( wgetch( win ) ) bs[3] = @compat UInt8( wgetch( win ) ) - return convert( UTF8String, bs ) + return convert( String, bs ) elseif 240 <= c <= 247 - bs = Array( UInt8, 4 ) + bs = Array{UInt8}( 4 ) bs[1] = @compat UInt8( c ) bs[2] = @compat UInt8( wgetch( win ) ) bs[3] = @compat UInt8( wgetch( win ) ) bs[4] = @compat UInt8( wgetch( win ) ) - return convert( UTF8String, bs ) + return convert( String, bs ) elseif 248 <= c <= 251 - bs = Array( UInt8, 5 ) + bs = Array{UInt8}( 5 ) bs[1] = @compat UInt8( c ) bs[2] = @compat UInt8( wgetch( win ) ) bs[3] = @compat UInt8( wgetch( win ) ) bs[4] = @compat UInt8( wgetch( win ) ) bs[5] = @compat UInt8( wgetch( win ) ) - return convert( UTF8String, bs ) + return convert( String, bs ) elseif 252 <= c <= 253 - bs = Array( UInt8, 6 ) + bs = Array{UInt8}( 6 ) bs[1] = @compat UInt8( c ) bs[2] = @compat UInt8( wgetch( win ) ) bs[3] = @compat UInt8( wgetch( win ) ) bs[4] = @compat UInt8( wgetch( win ) ) bs[5] = @compat UInt8( wgetch( win ) ) bs[6] = @compat UInt8( wgetch( win ) ) - return convert( UTF8String, bs ) + return convert( String, bs ) end end diff --git a/src/strutils.jl b/src/strutils.jl index 4cfba2a..4c405e0 100644 --- a/src/strutils.jl +++ b/src/strutils.jl @@ -1,5 +1,5 @@ function repr_symbol( s::Symbol ) - v = utf8(string(s)) + v = string(s) if length(v) == 0 v = ":\"\"" elseif match( r"^[a-zA-Z_][0-9a-zA-Z_]*$", v ) != nothing @@ -10,12 +10,8 @@ function repr_symbol( s::Symbol ) v end -function delete_char_before( s::ASCIIString, p::Int ) - return (s[1:p-2] * s[p:end], max(p-1,1) ) -end - #delete a code_point before the p "width" position -function delete_char_before( s::UTF8String, p::Int ) +function delete_char_before( s::String, p::Int ) local totalskip::Int = 0 local lastj::Int = 0 local lastcw::Int = 0 @@ -46,13 +42,9 @@ function delete_char_before( s::UTF8String, p::Int ) return (s[1:chr2ind(s,lastj-1)], p-lastcw) end -function delete_char_at( s::ASCIIString, p::Int ) - return s[1:p-1] * s[p+1:end] -end - # delete at least 1 code point, could be more if there # are trailing zero-width codepoints. -function delete_char_at( s::UTF8String, p::Int ) +function delete_char_at( s::String, p::Int ) local totalskip::Int = 0 local lastj::Int = 0 for (j,c) in enumerate( s ) @@ -75,7 +67,7 @@ end # TODO: test this thoroughly!! # Insert a (short) string at the "p" position # p is interpreted as the width position -function insertstring{T<:AbstractString}( s::UTF8String, ch::T, p::Int, overwrite::Bool ) +function insertstring{T<:AbstractString}( s::String, ch::T, p::Int, overwrite::Bool ) wskip = p-1 local totalskip::Int = 0 chwidth = strwidth( ch ) @@ -191,7 +183,7 @@ end function wordwrap{T<:AbstractString}( x::T, width::Int ) spaceleft = width - lines = UTF8String[] + lines = String[] currline = convert( T,"" ) words = @compat split( x, " ", keep=true ) # don't keep empty words for w in words @@ -241,7 +233,7 @@ function levenstein_distance( s1, s2 ) return v1[end] end -function longest_common_prefix( s1::UTF8String, s2::UTF8String ) +function longest_common_prefix( s1::String, s2::String ) m = min( length( s1 ), length( s2 ) ) lcpidx = 0 for i in 1:m diff --git a/src/twcalendar.jl b/src/twcalendar.jl index 61ad34c..e31490b 100644 --- a/src/twcalendar.jl +++ b/src/twcalendar.jl @@ -16,7 +16,7 @@ y,Y : add/subtract a year """ type TwCalendarData showHelp::Bool - helpText::UTF8String + helpText::String date::Date cursorweekofmonth::Int # cached "nth week" in the current month containing date, 1-based geometry::@compat Tuple{Int, Int} # rows x cols in months diff --git a/src/twdftable.jl b/src/twdftable.jl index 4641270..695a493 100644 --- a/src/twdftable.jl +++ b/src/twdftable.jl @@ -31,7 +31,7 @@ end type TwTableColInfo name::Symbol - displayname::UTF8String + displayname::String format::FormatHints aggr::Any end @@ -64,7 +64,7 @@ function getindex( n::TwDfTableNode, c::Symbol ) context = n.context.value aggr = context.allcolInfo[ c ].aggr f = liftAggrSpecToFunc( c, aggr ) - ret = f( n.subdataframe ) + ret = Base.invokelatest(f, n.subdataframe ) if typeof( ret ) <: AbstractDataFrame ret = ret[1][1] # first col, first row end @@ -75,7 +75,7 @@ function getindex( n::TwDfTableNode, c::Symbol ) end type TwTableView - name::UTF8String + name::String pivots::Array{Symbol,1} sortorder::Array{ (@compat Tuple{Symbol,Symbol}), 1 } # [ (:col1, :asc ), (:col2, :desc), ... ] columns::Array{ Symbol, 1 } @@ -83,7 +83,7 @@ type TwTableView end # convenient functions to construct views -function TwTableView( df::AbstractDataFrame, name::UTF8String; +function TwTableView( df::AbstractDataFrame, name::String; pivots = Symbol[], initdepth=1, colorder = Any[ "*" ], hidecols = Any[], sortorder = Any[] ) @@ -148,7 +148,7 @@ function TwTableView( df::AbstractDataFrame, name::UTF8String; error( "sortorder eltype expects Symbol, or Tuple{Symbol,Symbol}: " * string( eltype( sortorder ) ) ) end - TwTableView( utf8(name), pivots, actualsortorder, finalcolorder, initdepth ) + TwTableView( name, pivots, actualsortorder, finalcolorder, initdepth ) end # this is the widget data. all subnodes hold a weakref back to this to @@ -168,16 +168,16 @@ type TwDfTableData currentRight::Int # right most on-screen column colInfo::Array{ TwTableColInfo, 1 } # only the visible ones, maybe off-screen allcolInfo::Dict{ Symbol, TwTableColInfo } # including invisible ones - bottomText::UTF8String - helpText::UTF8String + bottomText::String + helpText::String initdepth::Int views::Array{ TwTableView, 1 } calcpivots::Dict{ Symbol, CalcPivot } - searchText::UTF8String + searchText::String # calculated dimension TwDfTableData() = new( TwDfTableNode(), Symbol[], Tuple{Symbol,Symbol}[], Any[], 0, 10, 1, 1, 1, 1, 1, 1, TwTableColInfo[], - Dict{Symbol,TwTableColInfo}(), "", defaultTableHelpText, 1, TwTableView[], Dict{Symbol,CalcPivot}(),utf8("") ) + Dict{Symbol,TwTableColInfo}(), "", defaultTableHelpText, 1, TwTableView[], Dict{Symbol,CalcPivot}(),"" ) end #TODO: allow Regex in formatHints and aggrHints @@ -192,7 +192,7 @@ function newTwDfTable( scr::TwObj, df::DataFrame; formatHints = Dict{Any,FormatHints}(), # Symbol/Type -> FormatHints aggrHints = Dict{Any,Any}(), # Symbol/Type -> string/symbol/expr/function widthHints = Dict{Symbol,Int}(), - headerHints = Dict{Symbol,UTF8String}(), + headerHints = Dict{Symbol,String}(), bottomText = defaultTableBottomText, views = Dict{Symbol,Any}[], calcpivots = Dict{Symbol,CalcPivot}() ) @@ -205,7 +205,7 @@ function newTwDfTable( scr::TwObj, df::DataFrame; obj.data.rootnode.subdataframe = df obj.data.rootnode.context = WeakRef( obj.data ) - mainV = TwTableView( df, utf8( "#Main"), pivots = pivots, + mainV = TwTableView( df, "#Main", pivots = pivots, initdepth=initdepth, sortorder=sortorder, colorder=colorder, hidecols=hidecols ) obj.data.pivots = mainV.pivots @@ -225,7 +225,7 @@ function newTwDfTable( scr::TwObj, df::DataFrame; vcolorder = get( d, :colorder, colorder ) vhidecols = get( d, :hidecols, hidecols ) vsortorder = get( d, :sortorder, sortorder ) - v = TwTableView( df, utf8( vname ), pivots = vpivots, initdepth = vinitdepth, + v = TwTableView( df, vname, pivots = vpivots, initdepth = vinitdepth, sortorder=vsortorder, colorder = vcolorder, hidecols = vhidecols ) push!( obj.data.views, v ) end @@ -292,7 +292,7 @@ function expandnode( n::TwDfTableNode, depth::Int=1 ) pvtby = setdiff( calcpvt.by, npivots ) f = liftCalcPivotToFunc( pvtspec, pvtby ) if isempty( pvtby ) - colvalues = f( n.subdataframe ) + colvalues = Base.invokelatest(f, n.subdataframe ) # Note that setindex! doesn't work for subdataframe # And we most certainly don't want to mutate the original # dataframe (if the node n here is the rootnode) @@ -313,7 +313,7 @@ function expandnode( n::TwDfTableNode, depth::Int=1 ) # the lifted function expects us to provide # the aggregation spec on all needed columns, # as keyword arguments - df = f( n.subdataframe, nextpivot; kwargs... ) + df = Base.invokelatest(f, n.subdataframe, nextpivot; kwargs... ) gd = DataFrames.groupby( join( n.subdataframe, df, on=pvtby, kind=:left ), nextpivots ) end else @@ -348,13 +348,13 @@ function ordernode( n::TwDfTableNode ) if length( sortorder ) > 0 sort!( n.children, lt = (x,y) -> begin for sc in sortorder - if isna( x[sc[1]] ) - if !isna( y[sc[1]] ) + if ismissing( x[sc[1]] ) + if !ismissing( y[sc[1]] ) return false else continue end - elseif isna( y[sc[1]] ) + elseif ismissing( y[sc[1]] ) return true end if x[sc[1]] == y[sc[1]] @@ -556,7 +556,7 @@ function draw( o::TwObj{TwDfTableData} ) end width = ( col == lastcol ? lastwidth : o.data.colInfo[ col ].format.width ) isred = false - if typeof( v ) == NAtype + if typeof( v ) == Missing str = ensure_length( "", width ) elseif typeof( v ) <: Real str = applyformat( v, o.data.colInfo[col].format ) @@ -954,7 +954,7 @@ function inject( o::TwObj{TwDfTableData}, token ) dorefresh = true end if o.data.datatreewidth+1_+1, widths[o.data.currentLeft:end] ) ) # with boundary + cumwidths = cumsum( map( x->x+1, widths[o.data.currentLeft:end] ) ) # with boundary widthrng = searchsorted( cumwidths, relx - o.data.datatreewidth - 1) o.data.currentCol = min( length( o.data.colInfo ), o.data.currentLeft + widthrng.start - 1 ) checkLeft() @@ -1035,9 +1035,9 @@ function inject( o::TwObj{TwDfTableData}, token ) end end elseif token == "p" - allcols = map(_->utf8(string(_)), names( o.data.rootnode.subdataframe ) ) - append!( allcols, map( _->utf8(string(_)), collect( keys( o.data.calcpivots ) ) ) ) - pvts = map( _->utf8(string(_)), o.data.pivots ) + allcols = map(x->string(x), names( o.data.rootnode.subdataframe ) ) + append!( allcols, map( x->string(x), collect( keys( o.data.calcpivots ) ) ) ) + pvts = map( x->string(x), o.data.pivots ) helper = newTwMultiSelect( o.screen.value, allcols, selected = pvts, title="Pivot order", orderable=true, substrsearch=true ) newpivots = activateTwObj( helper ) unregisterTwObj( o.screen.value, helper ) @@ -1053,8 +1053,8 @@ function inject( o::TwObj{TwDfTableData}, token ) end dorefresh = true elseif token == "c" - allcols = map(_->utf8(string(_)), names( o.data.rootnode.subdataframe ) ) - visiblecols = map( _->utf8(string(_.name)), o.data.colInfo ) + allcols = map(x->string(x), names( o.data.rootnode.subdataframe ) ) + visiblecols = map( x->string(x.name), o.data.colInfo ) helper = newTwMultiSelect( o.screen.value, allcols, selected = visiblecols, title="Visible columns & their order", orderable=true, substrsearch=true ) newcols = activateTwObj( helper ) unregisterTwObj( o.screen.value, helper ) @@ -1066,12 +1066,12 @@ function inject( o::TwObj{TwDfTableData}, token ) end dorefresh = true elseif token == "v" - allviews = map( _->_.name, o.data.views ) + allviews = map( x->x.name, o.data.views ) helper = newTwPopup( o.screen.value, allviews, substrsearch=true, title = "Views" ) vname = activateTwObj( helper ) unregisterTwObj( o.screen.value, helper ) if vname != nothing - idx = findfirst( _->_.name == vname, o.data.views ) + idx = findfirst( x->x.name == vname, o.data.views ) v = o.data.views[idx] o.data.colInfo = TwTableColInfo[] o.data.pivots = v.pivots @@ -1090,7 +1090,7 @@ function inject( o::TwObj{TwDfTableData}, token ) dorefresh=true end elseif token == "/" - helper = newTwEntry( o.screen.value, UTF8String; width=30, posy=:center, posx=:center, title = "Search: " ) + helper = newTwEntry( o.screen.value, String; width=30, posy=:center, posx=:center, title = "Search: " ) helper.data.inputText = o.data.searchText s = activateTwObj( helper ) unregisterTwObj( o.screen.value, helper ) @@ -1102,7 +1102,7 @@ function inject( o::TwObj{TwDfTableData}, token ) end dorefresh = true elseif token == "?" - helper = newTwEntry( o.screen.value, UTF8String; width=30, posy=:center, posx=:center, title = "Search: " ) + helper = newTwEntry( o.screen.value, String; width=30, posy=:center, posx=:center, title = "Search: " ) helper.data.inputText = o.data.searchText s = activateTwObj( helper ) unregisterTwObj( o.screen.value, helper ) @@ -1129,7 +1129,7 @@ function inject( o::TwObj{TwDfTableData}, token ) else v = node.subdataframesorted[ colsym ][ o.data.datalist[o.data.currentLine][2][end] ] end - if typeof( v ) != NAtype && !in( v, [ nothing, Void, Any ] ) + if typeof( v ) != Missing && !in( v, [ nothing, Void, Any ] ) tshow( v; title = string( colsym ), posx=:center, posy=:center ) dorefresh = true end @@ -1143,7 +1143,7 @@ function inject( o::TwObj{TwDfTableData}, token ) println( out, "\nRoot table stats" ) describe( out, o.data.rootnode.subdataframe[ colsym ] ) end - tshow( takebuf_string( out ); title = string( colsym ) * " stats", posx=:center,posy=:center) + tshow( String( take!(out) ); title = string( colsym ) * " stats", posx=:center,posy=:center) dorefresh = true else retcode = :pass # I don't know what to do with it diff --git a/src/twentry.jl b/src/twentry.jl index 877e7f7..ff47e26 100644 --- a/src/twentry.jl +++ b/src/twentry.jl @@ -1,6 +1,6 @@ # hand-crafted numeric and string input field -defaultEntryStringHelpText = utf8(""" +defaultEntryStringHelpText = """ <-, -> : move cursor ctrl-a : move cursor to start ctrl-e : move cursor to end @@ -8,9 +8,9 @@ ctrl-k : empty entry ctrl-r : Toggle insertion/overwrite mode Edges are highlighted if more beyond boundary -""") +""" -defaultEntryNumberHelpText = utf8(""" +defaultEntryNumberHelpText = """ <-, -> : move cursor ctrl-a : move cursor to start ctrl-e : move cursor to end @@ -22,9 +22,9 @@ e : (Floating Point only) exponent. 1e6 for 1,000,000.0 ctrl-r : Toggle insertion/overwrite mode Shft-up: If configured, increase value by a tick-size Shft-dn: If configured, decrease value by a tick-size -""") +""" -defaultEntryDateHelpText = utf8(""" +defaultEntryDateHelpText = """ Format : YYYY-MM-DD standard, but allows formats such as 20140101, 1/1/2014, 1Jan2014, 1 January 2014 2014.01.01 @@ -37,12 +37,12 @@ ctrl-r : Toggle insertion/overwrite mode ? : View calendar Shft-up: If configured, increase value by a tick-size Shft-dn: If configured, decrease value by a tick-size -""") +""" type TwEntryData valueType::DataType showHelp::Bool - helpText::UTF8String - inputText::UTF8String + helpText::String + inputText::String cursorPos::Int # where is the next char going to be fieldLeftPos::Int # what is the position of the first char on the field tickSize::Any @@ -53,9 +53,9 @@ type TwEntryData precision::Int commas::Bool stripzeros::Bool - conversion::ASCIIString + conversion::String function TwEntryData( dt::DataType ) - o = new( dt, false, utf8(""), utf8(""), 1, 1, 0, true, false, false, false, + o = new( dt, false, "", "", 1, 1, 0, true, false, false, false, -1, true, true, "" ) if dt <: AbstractString o.helpText = defaultEntryStringHelpText @@ -88,7 +88,7 @@ end # y and x is relative to parentwin function newTwEntry( parent::TwObj, dt::DataType; width::Real=30,posy::Any=:staggered,posx::Any=:staggered, - box=true, showHelp=true, titleLeft=true, title = utf8(""), + box=true, showHelp=true, titleLeft=true, title = "", precision=-1, stripzeros= (precision == -1), conversion="" ) data = TwEntryData( dt ) @@ -343,7 +343,7 @@ function inject( o::TwObj{TwEntryData}, token ) else beep() end - elseif o.data.valueType == Bool && typeof( token ) <: AbstractString && isprint( token ) + elseif o.data.valueType == Bool && typeof( token ) <: AbstractString && all(isprint, token ) if token == "t" o.data.inputText = "true" o.data.cursorPos = 1 @@ -434,7 +434,7 @@ function inject( o::TwObj{TwEntryData}, token ) insertchar( token ) dorefresh = true end - elseif typeof( token ) <: AbstractString && o.data.valueType <: AbstractString && isprint( token ) + elseif typeof( token ) <: AbstractString && o.data.valueType <: AbstractString && all(isprint, token ) insertchar( token ) checkcursor() dorefresh = true @@ -509,6 +509,7 @@ function evalNFormat( data::TwEntryData, s::AbstractString, fieldcount::Int ) else v = parse( dt, stmp ) end + catch end if v != nothing v = convert(dt, v) @@ -525,6 +526,7 @@ function evalNFormat( data::TwEntryData, s::AbstractString, fieldcount::Int ) else v = parse( dt.types[1], stmp ) end + catch end if v != nothing v = convert( dt, v) @@ -545,6 +547,7 @@ function evalNFormat( data::TwEntryData, s::AbstractString, fieldcount::Int ) tail = stmp[dpos+1:end] fv = parse( dt.types[2], tail ) // ( 10 ^ length(tail) ) end + catch end if iv != nothing && fv != nothing v = iv + (sign(iv) > 0? fv : -fv ) @@ -560,6 +563,7 @@ function evalNFormat( data::TwEntryData, s::AbstractString, fieldcount::Int ) else v = parse( dt, stmp ) end + catch end if v != nothing v = convert( dt, v) @@ -568,7 +572,7 @@ function evalNFormat( data::TwEntryData, s::AbstractString, fieldcount::Int ) elseif dt <: Date v = nothing s = strip( s ) - res = Compat.@Dict( r"^[0-9]{2}[a-z]{3}[0-9]{4}$"i => "dduuuyyyy", + res = Dict( r"^[0-9]{2}[a-z]{3}[0-9]{4}$"i => "dduuuyyyy", r"^[0-9][a-z]{3}[0-9]{4}$"i => "duuuyyyy", r"^[0-9]{2}[a-z]{3}[0-9]{2}$"i => "dduuuyy", r"^[0-9][a-z]{3}[0-9]{2}$"i => "duuuyy", @@ -590,6 +594,7 @@ function evalNFormat( data::TwEntryData, s::AbstractString, fieldcount::Int ) if m != nothing try v = Date( s, f ) + catch end if v != nothing fmt = f @@ -630,7 +635,7 @@ end function helptext( o::TwObj{TwEntryData} ) if !o.data.showHelp - return utf8("") + return "" end o.data.helpText end diff --git a/src/twfunc.jl b/src/twfunc.jl index ef97fd9..5d2a529 100644 --- a/src/twfunc.jl +++ b/src/twfunc.jl @@ -1,4 +1,4 @@ -defaultFuncHelpText = utf8(""" +defaultFuncHelpText = """ PgUp/PgDn : method list navigation Up/Dn : method list navigation Left/Right : search term cursor control @@ -12,7 +12,7 @@ Shift-left/right : Navigate method list left and right Ctrl-Sht-lft/rgt : Jump method list to left and right edge F6 : explore Method as tree F8 : edit method -""") +""" type TwFuncData datalist::Array{Any,1} @@ -23,24 +23,32 @@ type TwFuncData currentLine::Int currentLeft::Int showLineInfo::Bool # e.g.1/100 1.0% at top right corner - bottomText::UTF8String + bottomText::String showHelp::Bool - helpText::UTF8String + helpText::String TwFuncData() = new( Method[], 0, 0, nothing, - 1, 1, 1, true, utf8(""), true, defaultFuncHelpText ) + 1, 1, 1, true, "", true, defaultFuncHelpText ) +end + +function argName(s, n) + try + return s.types[n] + catch + return argName(s.body, n) + end end # the ways to use it: # exact dimensions known: h,w,y,x, content to add later # exact dimensions unknown, but content known and content drives dimensions function newTwFunc( scr::TwObj, ms::Array{Method,1}; kwargs... ) - ns = UTF8String[] # names - sig = UTF8String[] - files = UTF8String[] + ns = String[] # names + sig = String[] + files = String[] lines = Int[] for m in ms - push!( ns, utf8( string( m.func.code.name ) ) ) - push!( sig, utf8( string( m.sig ) ) ) + push!( ns, string( m.name ) ) + push!( sig, string( m.sig ) ) tv, decls, file, line = Base.arg_decl_parts(m) push!( files, string( file ) ) push!( lines, line ) @@ -50,10 +58,10 @@ function newTwFunc( scr::TwObj, ms::Array{Method,1}; kwargs... ) sig = sig, file = files, line = lines, - nargs = Int[ length(m.sig) for m in ms ], - arg1t = UTF8String[ (length(m.sig)>=1 ? ensure_length(utf8(m.sig[1]),35,false) : "") for m in ms ], - arg2t = UTF8String[ (length(m.sig)>=2 ? ensure_length(utf8(m.sig[2]),35,false) : "") for m in ms ], - arg3t = UTF8String[ (length(m.sig)>=3 ? ensure_length(utf8(m.sig[3]),35,false) : "") for m in ms ] + nargs = Int[ m.nargs for m in ms ], + arg1t = String[ (m.nargs>=1 ? ensure_length(string(argName(m.sig,1)),35,false) : "") for m in ms ], + arg2t = String[ (m.nargs>=2 ? ensure_length(string(argName(m.sig,2)),35,false) : "") for m in ms ], + arg3t = String[ (m.nargs>=3 ? ensure_length(string(argName(m.sig,3)),35,false) : "") for m in ms ] ) colorder = extractkwarg!( kwargs, :colorder, [ :name, :sig, :nargs, "*" ] ) pivots = extractkwarg!( kwargs, :pivots, [ ] ) diff --git a/src/twlist.jl b/src/twlist.jl index 3f05488..41a8d7c 100644 --- a/src/twlist.jl +++ b/src/twlist.jl @@ -14,7 +14,7 @@ function newTwList( scr::TwObj; canvaswidth = 128, box=true, horizontal=false, - title=utf8(""), + title="", showLineInfo=true) obj = TwObj( TwListData(), Val{:List } ) obj.box = box @@ -85,11 +85,11 @@ function update_list_canvas( o::TwObj{TwListData} ) end end if o.data.horizontal - o.data.canvasheight = maximum( map( _->objtype(_)==:List? _.data.canvasheight : _.height, ws ) ) - o.data.canvaswidth = sum( map( _->objtype(_)==:List? _.data.canvaswidth : _.width, ws ) ) + o.data.canvasheight = maximum( map( x->objtype(x)==:List? x.data.canvasheight : x.height, ws ) ) + o.data.canvaswidth = sum( map( x->objtype(x)==:List? x.data.canvaswidth : x.width, ws ) ) else - o.data.canvasheight = sum( map( _->objtype(_)==:List? _.data.canvasheight: _.height, ws ) ) - o.data.canvaswidth = maximum( map( _->objtype(_)==:List? _.data.canvaswidth : _.width, ws ) ) + o.data.canvasheight = sum( map( x->objtype(x)==:List? x.data.canvasheight: x.height, ws ) ) + o.data.canvaswidth = maximum( map( x->objtype(x)==:List? x.data.canvaswidth : x.width, ws ) ) end if !(typeof( o.window ) <: Ptr) o.height = o.data.canvasheight + (o.box?2:0) @@ -632,17 +632,17 @@ function helptext( o::TwObj{TwListData} ) focus = o.data.focus isrootlist = typeof( o.window ) <: Ptr if focus == 0 - return utf8("") + return "" end s = helptext( o.data.widgets[ focus ] ) if isrootlist -h = utf8(""" +h = """ ctrl-F4 : toggle navigation mode mouse-click: activate nearest widget ctrl-arrows: directional focus movements (normal arrows work too if not consumed by the current widget) tab/shift-tab: cycle through all widgets -""") +""" if s == "" # just the navigation text s = h else # merge the help text into a single window diff --git a/src/twmultiselect.jl b/src/twmultiselect.jl index 1cdc418..21e8e03 100644 --- a/src/twmultiselect.jl +++ b/src/twmultiselect.jl @@ -3,7 +3,7 @@ SELECTEDORDERABLE = 1 # whether selected items are orderable, selected always on top SELECTSUBSTR = 2 # search by substring (default by prefix) -defaultMultiSelectHelpText = utf8(""" +defaultMultiSelectHelpText = """ arrows : move cursor home : move to top end : move to bottom @@ -21,11 +21,11 @@ ctrl-r : Toggle insertion/overwrite mode ctrl-n : move to the next matched item ctrl-p : move to the previous matched item -""") +""" type TwMultiSelectData - choices::Array{UTF8String,1} - selected::Array{UTF8String,1} + choices::Array{String,1} + selected::Array{String,1} datalist::Array{Any, 1} maxchoicelength::Int searchbox::Any @@ -33,10 +33,10 @@ type TwMultiSelectData currentLeft::Int currentTop::Int selectmode::Int - helpText::UTF8String - TwMultiSelectData( arr::Array{UTF8String,1}, selected::Array{UTF8String,1} ) = new( arr, selected, Any[], 0, nothing, 1, 1, 1, 0, utf8("") ) + helpText::String + TwMultiSelectData( arr::Array{String,1}, selected::Array{String,1} ) = new( arr, selected, Any[], 0, nothing, 1, 1, 1, 0, "" ) end -TwMultiSelectData{T<:AbstractString,T2<:AbstractString}( arr::Array{T,1}, selected::Array{T2,1} ) = TwMultiSelectData( map( x->utf8( x ), arr ), map( x->utf8(x), selected ) ) +TwMultiSelectData{T<:AbstractString,T2<:AbstractString}( arr::Array{T,1}, selected::Array{T2,1} ) = TwMultiSelectData( map( x->x , arr ), map( x->x, selected ) ) # the ways to use it: # standalone panel @@ -44,10 +44,10 @@ TwMultiSelectData{T<:AbstractString,T2<:AbstractString}( arr::Array{T,1}, select # w include title width, if it's shown on the left function newTwMultiSelect{T<:AbstractString}( scr::TwObj, arr::Array{T,1}; posy::Any = :center,posx::Any = :center, - selected = UTF8String[], - title = utf8(""), maxwidth = 50, maxheight = 20, minwidth = 25, + selected = String[], + title = "", maxwidth = 50, maxheight = 20, minwidth = 25, orderable = false, substrsearch=false ) - obj = TwObj( TwMultiSelectData( arr, UTF8String[ utf8(string(_)) for _ in selected ] ), Val{ :MultiSelect } ) + obj = TwObj( TwMultiSelectData( arr, String[ string(x) for x in selected ] ), Val{ :MultiSelect } ) obj.box = true obj.title = title obj.borderSizeV= 1 @@ -62,7 +62,7 @@ function newTwMultiSelect{T<:AbstractString}( scr::TwObj, arr::Array{T,1}; obj.data.helpText = defaultMultiSelectHelpText obj.data.maxchoicelength = 0 if !isempty(arr) - obj.data.maxchoicelength = maximum( map(_->length(_), arr ) ) + obj.data.maxchoicelength = maximum( map(x->length(x), arr ) ) end h = 2 + min( length( arr ), maxheight ) @@ -70,8 +70,8 @@ function newTwMultiSelect{T<:AbstractString}( scr::TwObj, arr::Array{T,1}; link_parent_child( scr, obj, h,w, posy, posx ) - obj.data.searchbox = newTwEntry( obj, UTF8String, width=minwidth, posy=:bottom, posx=1, box=false ) - obj.data.searchbox.title = utf8("?") + obj.data.searchbox = newTwEntry( obj, String, width=minwidth, posy=:bottom, posx=1, box=false ) + obj.data.searchbox.title = "?" obj.data.searchbox.hasFocus = false obj end diff --git a/src/twobj.jl b/src/twobj.jl index 4813f6e..b2173ed 100644 --- a/src/twobj.jl +++ b/src/twobj.jl @@ -263,4 +263,4 @@ end refresh( o::TwObj ) = (erase(o);draw(o)) -helptext( _::TwObj ) = utf8("") +helptext( _::TwObj ) = "" diff --git a/src/twpopup.jl b/src/twpopup.jl index 67f7eb4..9c3aa6c 100644 --- a/src/twpopup.jl +++ b/src/twpopup.jl @@ -19,14 +19,14 @@ POPUPHIDEUNMATCHED = 4 POPUPSORTMATCHED = 8 POPUPALLOWNEW = 16 -defaultPopupHelpText = utf8(""" +defaultPopupHelpText = """ arrows : move cursor home : move to top end : move to bottom enter : select -""") +""" -defaultPopupQuickHelpText = utf8(""" +defaultPopupQuickHelpText = """ arrows : move item cursor home : move to top end : move to bottom @@ -40,10 +40,10 @@ ctrl-r : Toggle insertion/overwrite mode ctrl-n : move to the next matched item ctrl-p : move to the previous matched item -""") +""" type TwPopupData - choices::Array{UTF8String,1} + choices::Array{String,1} datalist::Array{Any, 1} maxchoicelength::Int searchbox::Any @@ -51,10 +51,10 @@ type TwPopupData currentLeft::Int currentTop::Int selectmode::Int - helpText::UTF8String - TwPopupData( arr::Array{UTF8String,1} ) = new( arr, Any[], maximum( map( z->length(z), arr ) ), nothing, 1, 1, 1, 0, utf8("") ) + helpText::String + TwPopupData( arr::Array{String,1} ) = new( arr, Any[], maximum( map( z->length(z), arr ) ), nothing, 1, 1, 1, 0, "" ) end -TwPopupData{ T<:AbstractString}( arr::Array{T, 1 } ) = TwPopupData( map( x->utf8( x ), arr ) ) +TwPopupData{ T<:AbstractString}( arr::Array{T, 1 } ) = TwPopupData( map( x-> x , arr ) ) # the ways to use it: # standalone panel @@ -62,10 +62,10 @@ TwPopupData{ T<:AbstractString}( arr::Array{T, 1 } ) = TwPopupData( map( x->utf8 # w include title width, if it's shown on the left function newTwPopup( scr::TwObj, arr::Array{Symbol,1}; posy::Any=:center,posx::Any=:center, - title = utf8(""), maxwidth = 50, maxheight = 15, minwidth = 20, + title = "", maxwidth = 50, maxheight = 15, minwidth = 20, quickselect = false, substrsearch=false, hideunmatched=false, sortmatched=false, allownew=false ) - return( newTwPopup( scr, map(x->utf8(string(x)),arr), + return( newTwPopup( scr, map(x->string(x),arr), posy=posy,posx=posx, title=title,maxwidth=maxwidth,maxheight=maxheight,minwidth=minwidth, quickselect=quickselect,substrsearch=substrsearch, @@ -74,7 +74,7 @@ end function newTwPopup{T<:AbstractString}( scr::TwObj, arr::Array{T,1}; posy::Any=:center,posx::Any=:center, - title = utf8(""), maxwidth = 50, maxheight = 15, minwidth = 20, + title = "", maxwidth = 50, maxheight = 15, minwidth = 20, quickselect = false, substrsearch=false, hideunmatched=false, sortmatched=false, allownew=false ) obj = TwObj( TwPopupData(arr), Val{ :Popup } ) obj.box = true @@ -111,8 +111,8 @@ function newTwPopup{T<:AbstractString}( scr::TwObj, arr::Array{T,1}; link_parent_child( scr, obj, h, w, posy, posx ) - obj.data.searchbox = newTwEntry( obj, UTF8String; width=minwidth, posy=:bottom, posx = 1, box=false ) - obj.data.searchbox.title = utf8("?") + obj.data.searchbox = newTwEntry( obj, String; width=minwidth, posy=:bottom, posx = 1, box=false ) + obj.data.searchbox.title = "?" obj.data.searchbox.hasFocus = false # so it looks dimmer than main cursor obj end diff --git a/src/twprogress.jl b/src/twprogress.jl index 41ed9b9..fad2337 100644 --- a/src/twprogress.jl +++ b/src/twprogress.jl @@ -6,11 +6,11 @@ type TwProgressData progress::Float64 showProgress::Bool cursorPos::Int # where is the progress bar cursor - text::UTF8String + text::String redrawTime::Float64 statusTime::Float64 startTime::Float64 - TwProgressData() = new( RemoteRef(), RemoteRef(), 0.0, true, 1, utf8(""), time(), time(), time() ) + TwProgressData() = new( RemoteRef(), RemoteRef(), 0.0, true, 1, "", time(), time(), time() ) end twGlobProgressData = TwProgressData() @@ -23,7 +23,7 @@ function updateProgressChannel( status::Symbol, v::Any ) put!( twGlobProgressData.statusChannel, ( status, v ) ) end -function progressMessage( s::UTF8String ) +function progressMessage( s::String ) global twGlobProgressData st = :normal val = nothing @@ -34,11 +34,11 @@ function progressMessage( s::UTF8String ) end end if typeof( val ) <: Dict && eltype( val ) <: (Symbol, Any) - val[ :message ] = utf8(s) + val[ :message ] = s put!( twGlobProgressData.statusChannel, ( st, val ) ) else if st != :error && st != :done - put!( twGlobProgressData.statusChannel, (st, @compat Dict{Symbol,Any}( :message => utf8(s) ) ) ) + put!( twGlobProgressData.statusChannel, (st, @compat Dict{Symbol,Any}( :message => s ) ) ) end end end @@ -68,9 +68,9 @@ end # w include title width, if it's shown on the left # the function f takes no argument. It's started right-away # the function can call -# * TermWin.progressMessage( s::UTF8String ) # make sure height can accommodate the content +# * TermWin.progressMessage( s::String ) # make sure height can accommodate the content # * TermWin.progressUpdate( n::Float64 ) # 0.0 <= n <= 1.0 -function newTwProgress( scr::TwObj; height::Real=5, width::Real=40, posy::Any=:center,posx::Any=:center, box=true, title = utf8("") ) +function newTwProgress( scr::TwObj; height::Real=5, width::Real=40, posy::Any=:center,posx::Any=:center, box=true, title = "" ) global twGlobProgressData obj = TwObj( TwProgressData(), Val{ :Progress } ) obj.data = twGlobProgressData @@ -119,7 +119,7 @@ function inject( o::TwObj{TwProgressData}, token::Any ) if st == :init twGlobProgressData.startTime = t twGlobProgressData.progress = 0.0 - twGlobProgressData.text = utf8( "init" * strftime( " %H:%M:%S", time() ) ) + twGlobProgressData.text = "init" * strftime( " %H:%M:%S", time() ) elseif st == :error o.value = val retcode = :exit_nothing @@ -129,11 +129,11 @@ function inject( o::TwObj{TwProgressData}, token::Any ) else if typeof( val ) <: Dict && eltype( val ) <: (Symbol,Any) if haskey( val, :message ) && typeof( val[:message] ) <: AbstractString - twGlobProgressData.text = utf8( val[ :message ] ) + twGlobProgressData.text = val[ :message ] end if haskey( val, :progress ) && typeof( val[ :progress ] ) == Float64 twGlobProgressData.progress = val[ :progress ] - #twGlobProgressData.text = utf8( string( st ) * strftime( " %H:%M:%S", time() ) ) + #twGlobProgressData.text = string( st ) * strftime( " %H:%M:%S", time() ) end end dorefresh = true diff --git a/src/twtree.jl b/src/twtree.jl index 49bf8a2..2bd164e 100644 --- a/src/twtree.jl +++ b/src/twtree.jl @@ -1,4 +1,4 @@ -defaultTreeHelpText = utf8(""" +defaultTreeHelpText = """ PgUp/PgDn, Arrow keys : standard navigation ,: toggle leaf expansion @@ -12,14 +12,14 @@ F6 : popup window for value Shift-F6 : popup window for type n, p : Move to next/previous matched line m : (Module Only) toggle export-only vs all names -""") +""" modulenames = Dict{ Module, Array{ Symbol, 1 } }() moduleallnames = Dict{ Module, Array{ Symbol, 1 } }() typefields = Dict{ Any, Array{ Symbol, 1 } }() typefields[ Method ] = [ :sig, :isstaged ] -typefields[ VERSION < v"0.5-" ? LambdaStaticData : LambdaInfo ] = [ :name, :module, :file, :line ] +#typefields[ VERSION < v"0.5-" ? LambdaStaticData : LambdaInfo ] = [ :name, :module, :file, :line ] typefields[ DataType ] = [ :name, :super, Symbol( "abstract" ), :mutable, :parameters ] typefields[ TypeName ] = [ :name, :module, :primary ] @@ -37,23 +37,23 @@ type TwTreeData currentLine::Int currentLeft::Int showLineInfo::Bool # e.g.1/100 1.0% at top right corner - bottomText::UTF8String + bottomText::String showHelp::Bool - helpText::UTF8String - searchText::UTF8String + helpText::String + searchText::String moduleall::Bool function TwTreeData() log( "TwTreeData 0") rv = new( Dict{ Any, Bool }(), Any[], 0, 0, 0, 0, 1, 1, 1, true, - utf8(""), true, utf8(defaultTreeHelpText), utf8(""), true ) + "", true, defaultTreeHelpText, "", true ) log( "TwTreeData 1") return( rv ) end end function newTwTree( scr::TwObj, ex; height::Real=0.8,width::Real=0.8,posy::Any=:staggered, posx::Any=:staggered, - title::UTF8String = utf8( string( typeof( ex ) ) ), box::Bool=true, showLineInfo::Bool=true, showHelp::Bool=true, - bottomText::UTF8String = utf8("") ) + title::String = string( typeof( ex ) ), box::Bool=true, showLineInfo::Bool=true, showHelp::Bool=true, + bottomText::String = "" ) log( "newTwTree 0") obj = TwObj( TwTreeData(), Val{ :Tree } ) log( "newTwTree 1") @@ -80,7 +80,7 @@ end # skiplines are hints where we should not draw the vertical lines to the left # because it corresponds the end of some list at a lower depth level -function tree_data{T}( x::Any, name::UTF8String, list::Array{T,1}, openstatemap::Dict{ Any, Bool }, stack::Array{Any,1}, skiplines::Array{Int,1}=Int[], moduleall::Bool = true ) +function tree_data{T}( x::Any, name::String, list::Array{T,1}, openstatemap::Dict{ Any, Bool }, stack::Array{Any,1}, skiplines::Array{Int,1}=Int[], moduleall::Bool = true ) global modulenames, typefields isexp = haskey( openstatemap, stack ) && openstatemap[ stack ] typx = typeof( x ) @@ -141,7 +141,7 @@ function tree_data{T}( x::Any, name::UTF8String, list::Array{T,1}, openstatemap: subname = "[" * repeat( " ", szdigits - length(istr)) * istr * "]" newstack = copy( stack ) push!( newstack, i ) - intern_tree_data( a, utf8(subname), newstack, i==len ) + intern_tree_data( a, subname, newstack, i==len ) end end elseif typx <: Associative @@ -167,7 +167,7 @@ function tree_data{T}( x::Any, name::UTF8String, list::Array{T,1}, openstatemap: end newstack = copy( stack ) push!( newstack, k ) - intern_tree_data( v, utf8(subname), newstack, i==len ) + intern_tree_data( v, subname, newstack, i==len ) end end elseif typx == Function @@ -187,7 +187,7 @@ function tree_data{T}( x::Any, name::UTF8String, list::Array{T,1}, openstatemap: subname = "Method[" * repeat( " ", szdigits - length(istr)) * istr * "]" newstack = copy( stack ) push!( newstack, i ) - intern_tree_data( m, utf8(subname), newstack, i==len ) + intern_tree_data( m, subname, newstack, i==len ) end end elseif typx == Module && !isempty( stack ) # don't want to recursively descend @@ -225,6 +225,7 @@ function tree_data{T}( x::Any, name::UTF8String, list::Array{T,1}, openstatemap: if length(ns) > 20 sort!(ns) end + catch end typefields[ typx ] = ns end @@ -237,7 +238,7 @@ function tree_data{T}( x::Any, name::UTF8String, list::Array{T,1}, openstatemap: push!( list, (s, t, v, stack, expandhint, skiplines ) ) if isexp && !isempty( ns ) for (i,n) in enumerate(ns) - subname = utf8(string(n)) + subname = string(n) newstack = copy( stack ) push!( newstack, n ) try @@ -377,7 +378,7 @@ function inject( o::TwObj{TwTreeData}, token ) update_tree_data = ()->begin o.data.datalist = Any[] - tree_data( o.value, utf8(o.title), o.data.datalist, o.data.openstatemap, Any[], Int[], o.data.moduleall ) + tree_data( o.value, o.title, o.data.datalist, o.data.openstatemap, Any[], Int[], o.data.moduleall ) updateTreeDimensions(o) viewContentWidth = o.data.datatreewidth + o.data.datatypewidth+o.data.datavaluewidth + 2 end @@ -650,7 +651,7 @@ function inject( o::TwObj{TwTreeData}, token ) beep() end elseif token == "/" - helper = newTwEntry( o.screen.value, UTF8String; width=30, posy=:center, posx=:center, title = "Search: " ) + helper = newTwEntry( o.screen.value, String; width=30, posy=:center, posx=:center, title = "Search: " ) helper.data.inputText = o.data.searchText s = activateTwObj( helper ) unregisterTwObj( o.screen.value, helper ) @@ -707,6 +708,6 @@ function helptext( o::TwObj{TwTreeData} ) if o.data.showHelp o.data.helpText else - utf8("") + "" end end diff --git a/src/twtypes.jl b/src/twtypes.jl index 54883d7..9a2fe86 100644 --- a/src/twtypes.jl +++ b/src/twtypes.jl @@ -39,16 +39,16 @@ type TwObj{T,S} isVisible::Bool data::T value::Any # the logical "content" that this object contains (return value if editable) - title::UTF8String + title::String listeners::Dict{ Symbol, Array } # event=>array of registered listeners. each listener is of the type (o, ev)->Void - function TwObj( data::T ) + function TwObj{T,S}( data::T ) where {T,S} log( "TwObj datatype=" * string( T ) * " TwObjSubtype="*string(S) ) x = new( WeakRef(), 0, nothing, nothing, 0, 0, 0, 0, false, 0, 0, - true, true, false, true, data, nothing, utf8(""), Dict{Symbol, Array{Function,1} }() ) + true, true, false, true, data, nothing, "", Dict{Symbol, Array{Function,1} }() ) finalizer( x, y->begin global rootwin if y.panel != nothing @@ -87,9 +87,9 @@ type TwListData canvaslocy::Int # 0-based showLineInfo::Bool navigationmode::Bool - bottomText::UTF8String + bottomText::String function TwListData() - ret = new( false, TwObj[], 0, 0, 0, nothing, 0, 0, false, false, utf8("") ) + ret = new( false, TwObj[], 0, 0, 0, nothing, 0, 0, false, false, "" ) finalizer( ret, y->begin if y.pad != nothing delwin( y.pad ) @@ -99,7 +99,7 @@ type TwListData end end -typealias TwScreen TwObj{TwScreenData} +const TwScreen = TwObj{TwScreenData} function TwObj{T,S}( d::T, ::Type{Val{S}} ) return( TwObj{T,S}(d) ) diff --git a/src/twviewer.jl b/src/twviewer.jl index bea7634..c4867d8 100644 --- a/src/twviewer.jl +++ b/src/twviewer.jl @@ -16,12 +16,12 @@ type TwViewerData currentLine::Int currentLeft::Int showLineInfo::Bool # e.g.1/100 1.0% at top right corner - bottomText::UTF8String + bottomText::String trackLine::Bool showHelp::Bool - helpText::UTF8String + helpText::String tabWidth::Int - TwViewerData() = new( UTF8String[], 0, 0, 1, 1, 1, true, "", false, true, defaultViewerHelpText, 4 ) + TwViewerData() = new( String[], 0, 0, 1, 1, 1, true, "", false, true, defaultViewerHelpText, 4 ) end # the ways to use it: