runtime(termdebug): Change some variables to Enums

Commit: 
https://github.com/vim/vim/commit/549ecc86365dc625e71e10b958525867c47e1cda
Author: Yinzuo Jiang <jiangyin...@foxmail.com>
Date:   Sat Jun 22 16:28:19 2024 +0200

    runtime(termdebug): Change some variables to Enums
    
    Problem:  The types of some script variables in Termdebug
              can be changed for readability
    Solution: Change the type of some vars from string to `enum`
              (Yinzuo Jiang)
    
    closes: #15068
    
    Signed-off-by: Yinzuo Jiang <jiangyin...@foxmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim 
b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
index a09accbdb..f87cabf58 100644
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -4,7 +4,7 @@ vim9script
 
 # Author: Bram Moolenaar
 # Copyright: Vim license applies, see ":help license"
-# Last Change: 2024 Jun 20
+# Last Change: 2024 Jun 22
 # Converted to Vim9: Ubaldo Tiberi <ubaldo.tib...@gmail.com>
 
 # WORK IN PROGRESS - The basics works stable, more to come
@@ -58,9 +58,14 @@ g:termdebug_is_running = false
 command -nargs=* -complete=file -bang Termdebug StartDebug(<bang>0, <f-args>)
 command -nargs=+ -complete=file -bang TermdebugCommand 
StartDebugCommand(<bang>0, <f-args>)
 
+enum Way
+  Prompt,
+  Terminal
+endenum
+
 # Script variables declaration. These variables are re-initialized at every
 # Termdebug instance
-var way: string
+var way: Way
 var err: string
 
 var pc_id: number
@@ -133,16 +138,15 @@ var saved_K_map: dict<any>
 var saved_plus_map: dict<any>
 var saved_minus_map: dict<any>
 
-
 def InitScriptVariables()
   if exists('g:termdebug_config') && has_key(g:termdebug_config, 'use_prompt')
-    way = g:termdebug_config['use_prompt'] ? 'prompt' : 'terminal'
+    way = g:termdebug_config['use_prompt'] ? Way.Prompt : Way.Terminal
   elseif exists('g:termdebug_use_prompt')
-    way = g:termdebug_use_prompt
+    way = g:termdebug_use_prompt ? Way.Prompt : Way.Terminal
   elseif has('terminal') && !has('win32')
-    way = 'terminal'
+    way = Way.Terminal
   else
-    way = 'prompt'
+    way = Way.Prompt
   endif
   err = ''
 
@@ -219,11 +223,11 @@ def SanityCheck(): bool
   var is_check_ok = true
   # Need either the +terminal feature or +channel and the prompt buffer.
   # The terminal feature does not work with gdb on win32.
-  if (way ==# 'prompt') && !has('channel')
+  if (way is Way.Prompt) && !has('channel')
     err = 'Cannot debug, +channel feature is not supported'
-  elseif way ==# 'prompt' && !exists('*prompt_setprompt')
+  elseif (way is Way.Prompt) && !exists('*prompt_setprompt')
     err = 'Cannot debug, missing prompt buffer support'
-  elseif way ==# 'prompt' && !empty(glob(gdb_cmd))
+  elseif (way is Way.Prompt) && !empty(glob(gdb_cmd))
     err = $"You have a file/folder named '{gdb_cmd}' in the current directory 
Termdebug may not work properly. Please exit and rename such a file/folder."
   elseif !empty(glob(asmbufname))
     err = $"You have a file/folder named '{asmbufname}' in the current 
directory Termdebug may not work properly. Please exit and rename such a 
file/folder."
@@ -305,6 +309,9 @@ def StartDebug_internal(dict: dict<any>)
     return
   endif
 
+  # Uncomment this line to write logging in "debuglog".
+  # call ch_logfile('debuglog', 'w')
+
   InitScriptVariables()
   if !SanityCheck()
     return
@@ -314,9 +321,6 @@ def StartDebug_internal(dict: dict<any>)
     doauto <nomodeline> User TermdebugStartPre
   endif
 
-  # Uncomment this line to write logging in "debuglog".
-  # call ch_logfile('debuglog', 'w')
-
   # Assume current window is the source code window
   sourcewin = win_getid()
   var wide = 0
@@ -338,7 +342,7 @@ def StartDebug_internal(dict: dict<any>)
     vvertical = false
   endif
 
-  if way == 'prompt'
+  if way is Way.Prompt
     StartDebug_prompt(dict)
   else
     StartDebug_term(dict)
@@ -699,7 +703,7 @@ enddef
 # Send a command to gdb.  "cmd" is the string without line terminator.
 def SendCommand(cmd: string)
   ch_log($'sending to gdb: {cmd}')
-  if way == 'prompt'
+  if way is Way.Prompt
     ch_sendraw(gdb_channel, $"{cmd}
")
   else
     term_sendkeys(commbufnr, $"{cmd}
")
@@ -708,7 +712,7 @@ enddef
 
 # Interrupt or stop the program
 def StopCommand()
-  if way == 'prompt'
+  if way is Way.Prompt
     PromptInterrupt()
   else
     SendCommand('-exec-interrupt')
@@ -717,7 +721,7 @@ enddef
 
 # Continue the program
 def ContinueCommand()
-  if way == 'prompt'
+  if way is Way.Prompt
     SendCommand('continue')
   else
     # using -exec-continue results in CTRL-C in the gdb window not working,
@@ -729,7 +733,7 @@ enddef
 
 # This is global so that a user can create their mappings with this.
 def g:TermDebugSendCommand(cmd: string)
-  if way == 'prompt'
+  if way is Way.Prompt
     ch_sendraw(gdb_channel, $"{cmd}
")
   else
     var do_continue = false

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sL1zH-00B28A-Sw%40256bit.org.

Raspunde prin e-mail lui