summary refs log tree commit diff stats
path: root/lib/ui
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-21 16:31:04 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-21 16:53:50 -0400
commit6811143925384ba1cfda8b3e1b338b0cfb9ac6e3 (patch)
tree584ce88b40ab87828d6adbfdb6bef7a5d3046600 /lib/ui
parent176245208d40a9ca2ec324be7863a22819de29bc (diff)
downloadaerc-6811143925384ba1cfda8b3e1b338b0cfb9ac6e3.tar.gz
New account wizard, part one
Diffstat (limited to 'lib/ui')
-rw-r--r--lib/ui/text.go2
-rw-r--r--lib/ui/textinput.go31
2 files changed, 23 insertions, 10 deletions
diff --git a/lib/ui/text.go b/lib/ui/text.go
index 8aea8eb..2b82598 100644
--- a/lib/ui/text.go
+++ b/lib/ui/text.go
@@ -77,7 +77,7 @@ func (t *Text) Draw(ctx *Context) {
 		style = style.Reverse(true)
 	}
 	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', style)
-	ctx.Printf(x, 0, style, t.text)
+	ctx.Printf(x, 0, style, "%s", t.text)
 }
 
 func (t *Text) Invalidate() {
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index 4a5308e..ce443c3 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -10,14 +10,15 @@ import (
 
 type TextInput struct {
 	Invalidatable
-	cells  int
-	ctx    *Context
-	focus  bool
-	index  int
-	prompt string
-	scroll int
-	text   []rune
-	change []func(ti *TextInput)
+	cells    int
+	ctx      *Context
+	focus    bool
+	index    int
+	password bool
+	prompt   string
+	scroll   int
+	text     []rune
+	change   []func(ti *TextInput)
 }
 
 // Creates a new TextInput. TextInputs will render a "textbox" in the entire
@@ -31,6 +32,11 @@ func NewTextInput(text string) *TextInput {
 	}
 }
 
+func (ti *TextInput) Password(password bool) *TextInput {
+	ti.password = password
+	return ti
+}
+
 func (ti *TextInput) Prompt(prompt string) *TextInput {
 	ti.prompt = prompt
 	return ti
@@ -42,6 +48,7 @@ func (ti *TextInput) String() string {
 
 func (ti *TextInput) Set(value string) {
 	ti.text = []rune(value)
+	ti.index = len(ti.text)
 }
 
 func (ti *TextInput) Invalidate() {
@@ -51,7 +58,13 @@ func (ti *TextInput) Invalidate() {
 func (ti *TextInput) Draw(ctx *Context) {
 	ti.ctx = ctx // gross
 	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
-	ctx.Printf(0, 0, tcell.StyleDefault, "%s%s", ti.prompt, string(ti.text))
+	if ti.password {
+		x := ctx.Printf(0, 0, tcell.StyleDefault, "%s", ti.prompt)
+		cells := runewidth.StringWidth(string(ti.text))
+		ctx.Fill(x, 0, cells, 1, '*', tcell.StyleDefault)
+	} else {
+		ctx.Printf(0, 0, tcell.StyleDefault, "%s%s", ti.prompt, string(ti.text))
+	}
 	cells := runewidth.StringWidth(string(ti.text[:ti.index]) + ti.prompt)
 	if cells != ti.cells && ti.focus {
 		ctx.SetCursor(cells, 0)
51'>251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451