# -*- tcl -*- # Maintenance Instruction: leave the 999999.xxx.x as is and use punkshell 'pmix make' or bin/punkmake to update from -buildversion.txt # module template: shellspy/src/decktemplates/vendor/punk/modules/template_module-0.0.3.tm # # Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem. # Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository. # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # (C) 2024 # # @@ Meta Begin # Application poshinfo 999999.0a1.0 # Meta platform tcl # Meta license # @@ Meta End # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # doctools header # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[manpage_begin shellspy_module_poshinfo 0 999999.0a1.0] #[copyright "2024"] #[titledesc {Module API}] [comment {-- Name section and table of contents description --}] #[moddesc {-}] [comment {-- Description at end of page heading --}] #[require poshinfo] #[keywords module] #[description] #[para] - # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[section Overview] #[para] overview of poshinfo #[subsection Concepts] #[para] - # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ ## Requirements # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[subsection dependencies] #[para] packages used by poshinfo #[list_begin itemized] package require Tcl 8.6- package require punk::config package require json ;#tcllib #toml, yaml? #*** !doctools #[item] [package {Tcl 8.6}] #[item] [package {punk::config}] #[item] [package {json}] # #package require frobz # #*** !doctools # #[item] [package {frobz}] #*** !doctools #[list_end] # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[section API] # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # oo::class namespace # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #tcl::namespace::eval poshinfo::class { #*** !doctools #[subsection {Namespace poshinfo::class}] #[para] class definitions #if {[tcl::info::commands [tcl::namespace::current]::interface_sample1] eq ""} { #*** !doctools #[list_begin enumerated] # oo::class create interface_sample1 { # #*** !doctools # #[enum] CLASS [class interface_sample1] # #[list_begin definitions] # method test {arg1} { # #*** !doctools # #[call class::interface_sample1 [method test] [arg arg1]] # #[para] test method # puts "test: $arg1" # } # #*** !doctools # #[list_end] [comment {-- end definitions interface_sample1}] # } #*** !doctools #[list_end] [comment {--- end class enumeration ---}] #} #} # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # Base namespace # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ tcl::namespace::eval poshinfo { tcl::namespace::export {[a-z]*} ;# Convention: export all lowercase #variable xyz #*** !doctools #[subsection {Namespace poshinfo}] #[para] Core API functions for poshinfo #[list_begin definitions] #proc sample1 {p1 n args} { # #*** !doctools # #[call [fun sample1] [arg p1] [arg n] [opt {option value...}]] # #[para]Description of sample1 # #[para] Arguments: # # [list_begin arguments] # # [arg_def tring p1] A description of string argument p1. # # [arg_def integer n] A description of integer argument n. # # [list_end] # return "ok" #} proc info_from_filename {fname} { #string based filename processing: we are deliberately avoiding test of file existence etc here if {$fname eq ""} { error "poshinfo::info_from_filename unable to determine name from empty string" } if {[string first . $fname] < 0} { #theoretically we could have a file without dots - but it's more likely an error in this context error "poshinfo::info_from_filename supplied value '$fname' doesn't look like a filename. Cowardly refusing to guess a shortname." } set ftail [file tail $fname] set rootname [file rootname $ftail] set format [string trimleft [file extension $ftail] .] set parts [split $rootname .] if {[lindex $parts end] eq "omp"} { set type omp set shortname [join [lrange $parts 0 end-1] .] } else { if {$rootname eq "schema"} { set type schema } else { set type unknown } set shortname $rootname } return [dict create shortname $shortname format $format type $type] } proc themes_dict {{globfor *}} { set running_config [punk::config::get running-config] set posh_themes_path [tcl::dict::get $running_config posh_themes_path] #posh_themes_path_extra ?? set themes [tcl::dict::create] if {[string length $posh_themes_path]} { if {[file exists $posh_themes_path]} { set files [glob -nocomplain -directory $posh_themes_path -tails $globfor] foreach ftail $files { set themeinfo [info_from_filename $ftail] set shortname [dict get $themeinfo shortname] dict set themeinfo path [file join $posh_themes_path $ftail] if {![dict exists $themes $shortname]} { dict set themes $shortname [list $themeinfo] } else { dict lappend themes $shortname $themeinfo } } } } return $themes } proc themes {{globfor *}} { set themes [themes_dict $globfor] set posh_theme [file normalize [punk::config::get_running_global posh_theme]] set t [textblock::class::table new "Posh Themes"] $t configure -show_header 1 -show_hseps 0 $t add_column -headers Shortname $t add_column -headers Path dict for {shortname themeinfolist} $themes { #hack - support just one for now set themeinfo [lindex $themeinfolist 0] set path [dict get $themeinfo path] $t add_row [list $shortname $path] set fg "" set bg "" switch -- [dict get $themeinfo type] { schema { set bg Web-orange } omp {} unknown { set bg Web-red } default { #we shouldn't be getting other values set bg Web-yellow } } if {$posh_theme eq [file normalize $path]} { set fg web-limegreen } if {"$fg$bg" ne ""} { $t configure_row [expr {[$t row_count]-1}] -ansibase [a+ {*}$fg {*}$bg] } } set result [$t print] $t destroy return $result } #*** !doctools #[list_end] [comment {--- end definitions namespace poshinfo ---}] } # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # Secondary API namespace # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ tcl::namespace::eval poshinfo::lib { tcl::namespace::export {[a-z]*} ;# Convention: export all lowercase tcl::namespace::path [tcl::namespace::parent] #*** !doctools #[subsection {Namespace poshinfo::lib}] #[para] Secondary functions that are part of the API #[list_begin definitions] #proc utility1 {p1 args} { # #*** !doctools # #[call lib::[fun utility1] [arg p1] [opt {?option value...?}]] # #[para]Description of utility1 # return 1 #} #*** !doctools #[list_end] [comment {--- end definitions namespace poshinfo::lib ---}] } # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ #*** !doctools #[section Internal] #tcl::namespace::eval poshinfo::system { #*** !doctools #[subsection {Namespace poshinfo::system}] #[para] Internal functions that are not part of the API #} # ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ ## Ready package provide poshinfo [tcl::namespace::eval poshinfo { variable pkg poshinfo variable version set version 999999.0a1.0 }] return #*** !doctools #[manpage_end]