Skip to content

Instantly share code, notes, and snippets.

@vtr0n
Last active November 24, 2020 21:24
Show Gist options
  • Save vtr0n/214df949e8cefaeae4890ba79b9ad073 to your computer and use it in GitHub Desktop.
Save vtr0n/214df949e8cefaeae4890ba79b9ad073 to your computer and use it in GitHub Desktop.
Npyscreen example 3
#!/usr/bin/env python3
from src import npyscreen
import random
class App(npyscreen.StandardApp):
def onStart(self):
# Set the theme. DefaultTheme is used by default
npyscreen.setTheme(npyscreen.Themes.ColorfulTheme)
self.addForm("MAIN", MainForm, name="Hello Medium!")
class InputBox(npyscreen.BoxTitle):
# MultiLineEdit now will be surrounded by boxing
_contained_widget = npyscreen.MultiLineEdit
class MainForm(npyscreen.FormBaseNew):
def create(self):
y, x = self.useable_space()
obj = self.add(npyscreen.BoxTitle, name="BoxTitle",
custom_highlighting=True, values=["first line", "second line"],
rely=y // 4, max_width=x // 2 - 5, max_height=y // 2)
self.add(InputBox, name="Boxed MultiLineEdit", footer="footer",
relx=x // 2, rely=2)
color1 = self.theme_manager.findPair(self, 'GOOD')
color2 = self.theme_manager.findPair(self, 'WARNING')
color3 = self.theme_manager.findPair(self, 'NO_EDIT')
color_list = [color1, color2, color3]
first_line_colors = [random.choice(color_list) for i in range(len("first line"))]
second_line_colors = [random.choice(color_list) for i in range(len("second"))]
# Fill the lines with custom colors
obj.entry_widget.highlighting_arr_color_data = [first_line_colors, second_line_colors]
MyApp = App()
MyApp.run()
@Ramphy0x90
Copy link

The code does not work correctly, you should print 2 lines with different character colors but it does not work

@Benjovengo
Copy link

This funcionality is only available on a specific fork of this project.
The link to the fork is https://github.com/vtr0n/npyscreen

But I think this should be added to this repo's code as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment