package main

import "log"
// import "strconv"
import "io/ioutil"
import "git.wit.org/wit/gui"

var fontNode *gui.Node
var fontsize string = ""

func xtermSettings(w *gui.Node) {
	if (w == nil) {
		gui.Config.Title = "Configure xterm"
		gui.Config.Width = 105
		gui.Config.Height = 105
		gui.Config.Exit = nil
		w = gui.NewWindow()
	}

	tab := w.AddTab("xtermSettings()", nil)

	// Select your fontsize
	gNode := tab.AddGroup("fontsize")
	fontsize = "16"
	fontNode = gNode.AddComboBox("fontsize", "8", "12", "16", "24", "32")
	fontNode.OnChanged = func () {
		fontsize = fontNode.GetText()
	}
	fontNode.SetText(fontsize)

//////////////   connect     /////////////////////////
	gNode = tab.AddGroup("Update")

	gNode.AddButton("setup .Xresources", func (*gui.Node) {
		log.Println("fontsize =", fontsize)

		// write out .Xresources file
		foo := []byte("xterm*faceName: Monospace\nxterm*faceSize: ")
		// bar := []byte(strconv.Itoa(fontsize) + "\n")
		bar := []byte(fontsize + "\n")
		foo = append(foo, bar...)
		ioutil.WriteFile("/home/jcarr/.Xresources", foo, 0644)

		cmd := "xrdb -merge ~/.Xresources; cat ~/.Xresources"
		xterm(cmd)
		log.Println("button click end")
	})

	gNode.AddButton("test xterm", func (*gui.Node) {
		cmd := "xterm"
		xterm(cmd)
	})
}
