Author Topic: Ask: Control Character: Backspace to erase the last character printed  (Read 6758 times)

0 Members and 1 Guest are viewing this topic.

RAYAKMAL

  • Guest
I want all my Autolisp code executed from menu and I need to hide the command that is used to call the functions.
Any idea how to use backspace control character (to erase the last character printed) in Windows OS?
I tried using "\b" but it didn't work. Did I do wrong?
Thanks for your help.
« Last Edit: July 18, 2014, 09:00:23 PM by RAYAKMAL »

BlackBox

  • King Gator
  • Posts: 3770
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #1 on: September 07, 2011, 08:40:08 PM »
I do not understand your question. Are you using a macro, or LISP?

Have tried:
Code: [Select]
^C^C^P

... Then your macro?

The "^P" is what causes a macro to be "silent."
"How we think determines what we do, and what we do determines what we get."

RAYAKMAL

  • Guest
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #2 on: September 07, 2011, 08:47:14 PM »
It's Autolisp.
E.q:

(defun C:MYfunc ()
  (repeat (strlen "MYFunc")
     (princ "\b")
  );end repeat
  ..
  ..
 
)

-----------------

I will put something in Menu file:
^C^C_MyFunc

Do you think I should write it :
^C^C^P_MyFunc ?

danallen

  • Guest
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #3 on: September 07, 2011, 09:52:37 PM »
if you want to erase a character, try this:
Code: [Select]
Command: (princ "ab\010c")(princ)
ac

^P does toggle MENUECHO on or off

Dan

BlackBox

  • King Gator
  • Posts: 3770
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #4 on: September 08, 2011, 12:28:00 AM »
Why would you write/use a function the uses princ only to "erase" the characters you sent to the command line???

Consider NOT doing all of that, and instead look into the CMDECHO, and NOMUTT system variables.
"How we think determines what we do, and what we do determines what we get."

RAYAKMAL

  • Guest
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #5 on: September 08, 2011, 07:41:38 AM »
@Dan. Thanks Dan, That's what I want  :-)
@Renderman. Thanks. My goals are:  1) If I can hide the function call (and users need to access the function through menu) this process helps users to memorize step by step instruction to accomplish things 2) I wanna 'hide' my lisp code from casual user (I still use Autolisp n Kelvinator, not VisualLisp)

danallen

  • Guest
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #6 on: September 08, 2011, 07:05:09 PM »
Why would you write/use a function the uses princ only to "erase" the characters you sent to the command line???

Try this:
Code: [Select]
(princ "\nProcessing ")
(repeat 2
  (foreach x (list "\\" "|" "/" "-")
    (prompt x)
    (command "delay" "500")
    (princ "\010")
    (princ)
  )
)

BlackBox

  • King Gator
  • Posts: 3770
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #7 on: September 08, 2011, 09:07:52 PM »
IMO - everything after the first line of code is wasted effort for some sort of 'neat' display effect (and that's fine, if you're into that). If you want that, check out DOSLib's progress bar function. :wink:
"How we think determines what we do, and what we do determines what we get."

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #8 on: September 09, 2011, 04:07:08 AM »
RM, that was actually the old way of indicating that the routine is processing. In the DOS days you had a turning bar in stead of a progress bar.

Something which princ'ed to the command line replacing the same character in turn with |, then /, then -, then \, and repeating. This way you indicated to the user that something's still happening: i.e. "No. ACad hasn't frozen!"

Of course you could try this alternative progress bar of mine: http://forums.augi.com/showpost.php?p=1104539&postcount=18
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #9 on: September 09, 2011, 07:44:26 AM »
Why would you write/use a function the uses princ only to "erase" the characters you sent to the command line???

Try this:

Use the "\r" character to avoid the need to backspace  :wink:

BlackBox

  • King Gator
  • Posts: 3770
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #10 on: September 09, 2011, 11:33:00 AM »
RM, that was actually the old way of indicating that the routine is processing. In the DOS days you had a turning bar in stead of a progress bar.

Something which princ'ed to the command line replacing the same character in turn with |, then /, then -, then \, and repeating. This way you indicated to the user that something's still happening: i.e. "No. ACad hasn't frozen!"

Of course you could try this alternative progress bar of mine: http://forums.augi.com/showpost.php?p=1104539&postcount=18

No, I understand it... I've been using Land Desktop for years. I've just never found the need, desire to actually incorporate it into my limited code library.

Again, this is not about me, so my opinion on this matter is of little worth, if not irrelevant. My apologies to the OP, as I did not intend on causing this tangent.

Why would you write/use a function the uses princ only to "erase" the characters you sent to the command line???

Try this:

Use the "\r" character to avoid the need to backspace  :wink:

This is the method I use for almost every LISP function I write (perhaps I should have posted that, Doh!). You'll see this in my code posts frequently.
"How we think determines what we do, and what we do determines what we get."

danallen

  • Guest
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #11 on: September 09, 2011, 09:42:48 PM »
Use the "\r" character to avoid the need to backspace  :wink:

What is that supposed to be used for? Testing I get this surprising result:
Code: [Select]
Command: (princ "abcd\refg")(princ)
efgd

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #12 on: September 10, 2011, 07:59:57 AM »
e.g.:

Code: [Select]
(defun _spinner ( / c )
    (setq c (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)
    (repeat 2 (foreach x '("\r-" "\r\\" "\r|" "\r/") (princ x) (command "_.delay" 200)))
    (setvar 'CMDECHO c)
    (princ)
)

Or:

Code: [Select]
(defun c:test ( / pt )
    (terpri)
    (while (setq pt (getpoint "\rPick Point: "))
        (entmakex (list (cons 0 "POINT") (cons 10 (trans pt 1 0))))
    )
    (princ)
)

danallen

  • Guest
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #13 on: September 11, 2011, 04:29:46 PM »
I see the return character \r is intended to backspace the entire line. I was confused by the end "d" from this test:
Code: [Select]
Command: (princ "abcd\refg")(princ)
efgd

I thought it was a bug until I figured out that the new text after return just overwrites:
Code: [Select]
Command: (princ "abcdefg\rABC")(princ)
ABCdefg

Thanks

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #14 on: September 11, 2011, 07:26:17 PM »
Not quite a 'backspace' since no text is deleted; the '\r' control character is a carriage return which instructs the output to start at the beginning of the same line, overwriting any existing text.

BlackBox

  • King Gator
  • Posts: 3770
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #15 on: September 11, 2011, 10:19:28 PM »
Similar to the "Initializing..." message displayed with AUTOLOAD function.
"How we think determines what we do, and what we do determines what we get."

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #16 on: September 12, 2011, 03:25:05 AM »
Yep, the \r (carriage return) can be seen as analogous to an old typewriter moving back to the start of a line. The \n new line is usually followed by that. Actually that's exactly what they do when sent to a printer (at least those old dot-matrix / daisy-wheel stuff).

The difference though is when you use \r on a screen you overwrite what was already on the line. Effectively erasing as you fill in new stuff. Usually it doesn't cause problems, though in the old days you tended to see flickering as the line of text got redrawn.

So back then it was a bit less processing to just backspace one char and replace just that one. On windows it doesn't make much difference since an update to one char invalidates the entire command palette in any case - thus cause a redraw of its entirety. It's just that the new hardware's so much faster at displaying these updates that you won't notice the difference between \r and \010.

Another place it was used quite often was to show a running counter which would backspace over the number portion of the message. Then replace just that with the new value. But again, these days it's not necessary. Though I'm starting to sound as if I'm advocating something I despise about current programming laxity: back in the 70's & 80's programs tended to be as efficient as possible. Since around the 90's programmers tended to say: "The hardware's fast & large enough, we don't need to worry so much about keeping it small and efficient."

It's just that in this particular case, it makes no difference which one you choose. You're stuck with the way windows updates its display, so changing one character or the entire line has the same processing & update effect.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

BlackBox

  • King Gator
  • Posts: 3770
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #17 on: September 12, 2011, 06:13:25 AM »
Though I'm starting to sound as if I'm advocating something I despise about current programming laxity: back in the 70's & 80's programs tended to be as efficient as possible. Since around the 90's programmers tended to say: "The hardware's fast & large enough, we don't need to worry so much about keeping it small and efficient."

I *heart* Apply, Lambda, and Mapcar. :-D LoL
"How we think determines what we do, and what we do determines what we get."

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Ask: Control Character: Backspace to erase the last character printed
« Reply #18 on: September 12, 2011, 11:09:26 AM »
I definitely like those too. They save a lot of programming  8) ... but when used in the correct places they don't necessarily make for "inefficient" programming. In Lisp they're actually quite efficient in themselves, it's when you try them in something like C# (which has to load the entire Linq libraries simply to use such constructs) when the overhead comes to play.

Actually even in those days-gone-by these functions were used in extremely efficient programming. Even to the point where it became an art-form  :lmao: . It's usually a case of the optimization is handled by the compiler / interpreter in such a way as to make for more efficient running code.

E.g. using a while loop with a counter variable extracting from a list of strings and running strcat to concatenate them all together would not only be a lot of typing, but would use at least twice the amount of RAM and probably be slower than simply using apply:
Code: [Select]
;; Iterative strcat of list
(defun strcat-list-1 (lst / str n)
  (setq n (length lst) str "")
  (while (> (setq n (1- n)) -1)
    (setq str (strcat (nth n lst) str))
  )
  str
)

;; Iterative strcat of list - using foreach
 (defun strcat-list-1a (lst / str)
   (setq str "")
   (foreach item lst
     (setq str (strcat str item))
   )
   str
 )

;; Recursive strcat of list
(defun strcat-list-2 (lst / )
  (if (cdr lst)
    (strcat (car lst) (strcat-list-2 (cdr lst)))
    (car lst)
  )
)

;; Minimal version using apply
(defun strcat-list-3 (lst / )
   (apply 'strcat lst)
 )
And the test:
Code: [Select]
_$ (setq lst '("This" " " "is" " " "a" " " "test."))
("This" " " "is" " " "a" " " "test.")
_$ (benchmark '((strcat-list-1 lst) (strcat-list-1a lst) (strcat-list-2 lst) (strcat-list-3 lst)))
Benchmarking ..................Elapsed milliseconds / relative speed for 32768 iteration(s):

    (STRCAT-LIST-3 LST)......1141 / 1.47 <fastest>
    (STRCAT-LIST-2 LST)......1313 / 1.27
    (STRCAT-LIST-1A LST).....1390 / 1.20
    (STRCAT-LIST-1 LST)......1672 / 1.00 <slowest>
So you can see the recursive & foreach are close. But the while is slow as molasses. The apply is a lot faster in comparison.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.