# -*- tcl -*-
# <20240327.1801.49>
######################################################
## TkCon Resource File    
after 40 [list puts "Loading rcfile [info script]"]
set ::tkcon::OPT(font) [font create myfont {*}[font configure TkFixedFont] -size 12 -weight bold]

# Keep 50 commands in history
set ::tkcon::OPT(history) 1000

# Use a pink prompt
set ::tkcon::COLOR(prompt) green1
######################################################
set ::tkcon::COLOR(bg) black
#     The background color for tkcon text widgets. 
#     Defaults to the operating system default (determined at startup).
# ::tkcon::COLOR(blink)
#     The background color of the electric brace highlighting, if on. 
#     Defaults to yellow.
set ::tkcon::COLOR(cursor) white
#     The background color for the insertion cursor in tkcon. 
#     Defaults to black.
# ::tkcon::COLOR(disabled)
#     The foreground color for disabled menu items. 
#     Defaults to dark grey.
set ::tkcon::COLOR(proc) SkyBlue
#     The foreground color of a recognized proc, if command highlighting is on.
#     Defaults to dark green.
# ::tkcon::COLOR(var)
set ::tkcon::COLOR(var) red
#     The background color of a recognized var, if command highlighting is on. 
#     Defaults to pink.
set ::tkcon::COLOR(prompt) CadetBlue1
#     The foreground color of the prompt as output in the console. 
#     Defaults to brown.
set ::tkcon::COLOR(stdin) green1
#     The foreground color of the stdin for the console. Defaults to black.
set ::tkcon::COLOR(stdout) SpringGreen
#     The foreground color of the stdout as output in the console. 
#     Defaults to blue.
# ::tkcon::COLOR(stderr)
#     The foreground color of stderr as output in the console. 
#     Defaults to red.
# ::tkcon::OPT(autoload)
#     Packages to automatically load into the slave interpreter (i.e. 'Tk'). 
#     This is a list. Defaults to {} (none).
# ::tkcon::OPT(blinktime)
#     The amount of time (in millisecs) that braced sections should blink for. 
#     Defaults to 500 (0.5 secs), must be at least 100.
# ::tkcon::OPT(blinkrange)
#     Whether to blink the entire range for electric brace matching or to 
#     just blink the actual matching braces 
#     (respectively 1 or 0, defaults to 1).
# ::tkcon::OPT(buffer)
#     The size of the console scroll buffer (in lines). 
#     Defaults to 512.
set ::tkcon::OPT(calcmode) 0
#     Whether to allow expr commands to be run at the command line without 
#     prefixing them with expr (just a convenience).
#     And it means some commands are evaluated as expressions NO-NO!
# ::tkcon::OPT(cols)
#     Number of columns for the console to start out with. 
#     Defaults to 80.
# ::tkcon::OPT(dead)
#     What to do with dead connected interpreters. If dead is leave, 
#     TkCon automatically exits the dead interpreter. If dead is ignore 
#     then it remains attached waiting for the interpreter to reappear. 
#     Otherwise TkCon will prompt you.
# ::tkcon::OPT(exec)
set ::tkcon::OPT(exec) {}
#     This corresponds to the -exec tkcon option (see tkcon(1)).
#  set ::tkcon::OPT(font) Bold
#     Font to use for tkcon text widgets (also specified with -font option). 
#     Defaults to the system default, or a fixed width equivalent.
# ::tkcon::OPT(gets)
#     Controls whether tkcon will overload the gets command to work with tkcon. 
#     The valid values are: congets (the default), which will redirect stdin 
#     requests to the tkcon window; gets, which will pop up a dialog to get 
#     input; and {} (empty string) which tells tkcon not to overload gets. 
#     This value must be set at startup to alter tkcon's behavior.
# ::tkcon::OPT(history)
#     The size of the history list to keep. 
#     Defaults to 48.
# ::tkcon::OPT(hoterrors)
#     Whether hot errors are enabled or not. When enabled, errors that are 
#     returned to the console are marked with a link to the error info that 
#     will pop up in an minimal editor. This requires more memory because 
#     each error that occurs will maintain bindings for this feature, as 
#     long as the error is in the text widget. 
#     Defaults to on.
# ::tkcon::OPT(library)
#     The path to any tcl library directories (these are appended to the 
#     auto_path when the after the resource file is loaded in).
# ::tkcon::OPT(lightbrace)
#     Whether to use the brace highlighting feature or not 
#     (respectively 1 or 0, defaults to 1).
# ::tkcon::OPT(lightcmd)
#     Whether to use the command highlighting feature or not 
#     (respectively 1 or 0, defaults to 1).
# ::tkcon::OPT(maineval)
#     A tcl script to execute in the main interpreter after the slave 
#     interpreter is created and the user interface is initialized.
# ::tkcon::OPT(maxlinelen)
#     A number that specifies the limit of long result lines. True result 
#     is still captured in $_ (and 'puts $_' works). 
#     Defaults to 0 (unlimited).
# ::tkcon::OPT(maxmenu)
#     A number that specifies the maximum number of packages to show vertically 
#     in the Interp->Packages menu before breaking into another column. 
#     Defaults to 15.
# ::tkcon::OPT(nontcl)
#     For those who might be using non-Tcl based Tk attachments, set this to 1. 
#     It prevents TkCon from trying to evaluate its own Tcl code in an 
#     attached interpreter. Also see my notes for non-Tcl based Tk interpreters.
# ::tkcon::OPT(prompt1)
#     Like tcl_prompt1, except it doesn't require you use puts. No equivalent 
#     for tcl_prompt2 is available (it's unnecessary IMHO). 
#     Defaults to {([file tail [pwd]]) [history nextid] % }.
# ::tkcon::OPT(rows)
#     Number of rows for the console to start out with. 
#     Defaults to 20.
# ::tkcon::OPT(scollypos)
#     Y scrollbar position. Valid values are left or right. 
#     Defaults to right.
# ::tkcon::OPT(showmenu)
#     Show the menubar on startup (
#     1 or 0, defaults to 1).
# ::tkcon::OPT(showmultiple)
#     Show multiple matches for path/proc/var name expansion 
#     (1 or 0, defaults to 1).
# ::tkcon::OPT(slaveeval)
#     A tcl script to execute in each slave interpreter right after it's 
#     created. This allows the user to have user defined info always 
#     available in a slave.

#     Example:


#     set ::tkcon::OPT(slaveeval) {
#         proc foo args { puts $args }
#         lappend auto_path .
#     }

# ::tkcon::OPT(slaveexit)
#     Allows the prevention of exit in slaves from exitting the entire 
#     application. If it is equal to exit, exit will exit as usual, otherwise 
#     it will just close down that interpreter (and any children). 
#     Defaults to close.
# ::tkcon::OPT(subhistory)
#     Allow history substitution to occur (0 or 1, defaults to 1). The 
#     history list is maintained in a single interpreter per TkCon console 
#     instance. Thus you have history which can range over a series of 
#     attached interpreters.
#
# Here we assume helper routines are located either in
# <here>/tkcon.b          (a sub dir of where we found this file) or
# in the same dir as tkconrc was found (usually the pkgIndex.tcl is there).

proc ::tkcon::getHelpers {c} {
  if {![winfo exists .tkcon.tab1] && [incr c] < 50} {
    after 40 [list ::tkcon::getHelpers $c]
    return
  }
  # puts "$c"
  if {![winfo exists .tkcon.tab1]} {
    puts "tkcon::getHelpers failed in wait for .tkcon.tab1"
    return
  }
  set here [file dir [info script]]/tkcon.d
  # we lookup the tkconrc package dir by way of having a tclIndex file
  # there which indexed "::tkcon::tkconrc.tcl"
  set there {}
  # force update of auto_index
  catch {::tkcon::foobarFunctions}
  if {[info exists ::auto_index(::tkcon::tkconrc)]} {
    set there [file dir [lindex $::auto_index(::tkcon::tkconrc) 1]]
  }
  #frputs here there pack
  # We "source" these in order since that matters (sometimes)
  foreach dir {here there} {
    if {[file isdir [set $dir]]} {
      foreach source [lsort [glob -nocomplain -directory [set $dir] *.tcl]] {
	if {[string match */pkgIndex.tcl $source]} {continue}
	if {[string match */tkconrc.tcl  $source]} {continue}
	# puts "$source $dir [set $dir]"
        # Log "sourcing $source"
	catch {source $source} duh
	if {$duh != {}} {
	  puts "$source $duh"
	}
      }
    }
  }
}

# Un comment the following if you want to source helper files
# which should be located in one or both of the following dirs:
#
# a.) The subdir tkcon.d of the dir this configuration file
#     (tkcon.cfg or .tkconrc) is located in 
# b.) The same dir the tkconrc.tcl file was sourced from. If loaded
#     from a package this will be the same dir as the pkgIndex.tcl
#     file for tkconrc.
#
# If you have namespace eval in these files or if you refer to vars
# in a name space be sure to use "::" infront of the namespace or
# you will end up in tkcon::<your name>, i.e. ::<your name> works
# but <your name> will give tkcon::<your name>. This is because
# getHelpers is in the tkcon namespace.
# Lets wait for our window...

  after 40 [list ::tkcon::getHelpers 0]
# Add the mains title to tkcons...
proc addTitle {} {
  set tkconWindow $::tkcon::PRIV(root)
  if {$tkconWindow == "."} {return}
  if {![winfo exists $tkconWindow]} {
    after 500 addTitle
    return
  } 
  wm title $::tkcon::PRIV(root) "[wm title $::tkcon::PRIV(root)]\
           ([wm title .])"
}
addTitle
 
  set foo "Tkconrc loaded"
