Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I tried to create a pull request, but it was not working properly. #131

Open
MostHated opened this issue Jun 11, 2019 · 1 comment
Open

Comments

@MostHated
Copy link

MostHated commented Jun 11, 2019

I wanted to share something I came up with, in case you were interested in adding it to the library. I tried to create a pull request, but even though I had it in a new branch, it kept on trying to include several other non-related commits.

I came up with this: which I put into textutil.go, line 235 - to the end of the function. The purpose of the code is, if you add term.SetOutputMode(term.Output256) ( I added it just after init like so):

func mainLoop() {
	ui.InitLibrary()
	defer ui.DeinitLibrary()
	
	// --- Newly added ---------------------
	term.SetOutputMode(term.Output256)

	ui.SetThemePath("themes")
	ui.SetCurrentTheme("verifier")

	createView()

	ui.MainLoop()
}

This tells the terminal to run in 256 color mode. The code I added below allows you to take advantage of the extra colors in a theme, at the same time as using the original specification, so you can have a mix of named colors as well as integer code. It also has a check to make sure your integer codes are between 0-255, and it only accepts the integers if it detects you have enabled Output256 mode. Otherwise it will just continue to use the normal template specifications.If you try to use an integer color code without first enabling, it gives you a specific error that you need to add it.

	var clr term.Attribute // ---- original code
	for _, item := range parts {
		item = strings.Trim(item, " ")
		item = strings.ToLower(item) // ---- original code

		if term.SetOutputMode(term.OutputCurrent) == term.Output256 {   // --------------- Newly added
			if c, err := strconv.Atoi(item); err == nil {
				if (c >= 0) && (c <= 255) {
					clr = term.Attribute(c)
					return clr
				} else {
					panic(fmt.Sprintf("Color integer must be between 0-255. Current value: %v", c))
				}
			}
		}

		if _, err := strconv.Atoi(item); err == nil {
			{
				panic(fmt.Sprintf("To use 0-255 integer color you must set terminal output mode: 'term.SetOutputMode(term.Output256)'"))
			}
		} else {
			c, ok := colorMap[item]
			if ok {
				clr |= c
				return clr
			}
		}
	} // -------------- Newly added

	return clr
} 

I was not sure if you were interested in adding more colors or not, but this is how I did it to make my GUI I showed in one of my other posts.

Thanks!
-MH

@VladimirMarkelov
Copy link
Owner

Thank you! I am sorry I missed you issue. I do not remember github sending me notifications about new issue maybe since the early 2019. Whether it was github trouble, or I overlooked all new issues but only after a new issue was added last week, I manually check the list of issues and found a few ones I have not replied to.

On the one hand, support 256 colors looks great. On the other hand, being on Windows 7 that has a console limited to 16 colors, I cannot test and debug 256-color mode effectively. It also means that I cannot include standard themes with 256-colors since they fail on Windows 7. I know, Windows 7 is unsupported by Microsoft since this year. But there are still a lot of people who keep using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants