Skip to content

Commit ec611b3

Browse files
committed
refactor!: drop Tcl 8.5 support and upgrade code
1 parent fb549db commit ec611b3

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

2048.tcl

+32-28
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#! /usr/bin/env tclsh
22
# The game 2048 implemented in Tcl.
33
# Version 1.0.0.
4-
# This code is released under the terms of the MIT license. See the file
5-
# LICENSE for details.
4+
#
5+
# This code is released under the terms of the MIT license.
6+
# See the file LICENSE for details.
7+
#
68
# More at:
7-
# - https://github.com/dbohdan/2048.tcl -- Git repository;
8-
# - https://wiki.tcl-lang.org/40557 -- discussion.
9+
# - https://github.com/dbohdan/2048.tcl -- Git repository
10+
# - https://wiki.tcl-lang.org/40557 -- discussion
911

10-
package require Tcl 8.5 9
12+
package require Tcl 8.6 9
1113

1214
namespace eval 2048 {
1315
namespace ensemble create
@@ -56,15 +58,18 @@ namespace eval 2048 {
5658
foreach cell $cellList {
5759
lassign $cell i j
5860
set c [get-cell $cell]
59-
set status [catch [list uplevel $script] cres copts]
60-
switch $status {
61-
2 {
62-
return -options [dict replace $copts -level 2] $cres
63-
}
64-
default {
65-
return -options $copts $cres
66-
}
61+
62+
try {
63+
uplevel $script
64+
} on ok {res opts} - \
65+
on error {res opts} - \
66+
on break {res opts} - \
67+
on continue {res opts} {
68+
return -options $opts $res
69+
} on return {res opts} {
70+
return -options [dict replace $opts -level 2] $res
6771
}
72+
6873
set-cell [list $i $j] $c
6974
}
7075
}
@@ -352,7 +357,7 @@ namespace eval 2048 {
352357

353358
switch [scan $playerInput %c] {
354359
3 {
355-
if {$playType eq random} {
360+
if {$playType eq {random}} {
356361
set playType user
357362
} else {
358363
quit-game 0
@@ -490,25 +495,24 @@ namespace eval 2048 {
490495
variable inputModeSaved {}
491496
variable inputMethod {}
492497
chan configure stdin -blocking 0
493-
if {![catch {package require twapi}]} {
498+
499+
try {
500+
package require twapi
501+
494502
set inputModeSaved [twapi::get_console_input_mode stdin]
495503
twapi::modify_console_input_mode stdin -lineinput false \
496504
-echoinput false
497505
set inputMethod twapi
498-
} else {
506+
} on error _ {
499507
catch {
500-
if {[auto_execok stty] ne {}} {
501-
if {[catch {set inputModeSaved [
502-
exec stty -g 2>@stderr]} eres eopts]} {
503-
return
504-
# TODO: Find other ways to save the state of the
505-
# terminal.
506-
}
507-
package require term::ansi::ctrl::unix
508-
package require term::ansi::send
509-
term::ansi::ctrl::unix::raw
510-
set inputMethod raw
511-
}
508+
set inputModeSaved [exec stty -g 2>@stderr]
509+
# TODO: Find other ways to save the state of the
510+
# terminal.
511+
512+
package require term::ansi::ctrl::unix
513+
package require term::ansi::send
514+
term::ansi::ctrl::unix::raw
515+
set inputMethod raw
512516
}
513517
}
514518

0 commit comments

Comments
 (0)