Take notes on the command line: Difference between revisions

no edit summary
m (syntax highlighting fixup automation)
No edit summary
Line 1,711:
fp:close()
end</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
M2000 Interpreter run M2000 environment, which is a Windows program (written in VB6). So for using console we have to use Kernel32 AttachConsole. When we start M2000.exe with a gsb file, the console of M2000 not opened until we execute a Show command or we use an input statement. So we can run this code without opening M2000 console. There is a tiny lag (observable) when start the environment (can open many times at the same time), there is a stack capacity check, and the M2000.exe make about 30MByte stack (from 1Mbyte the default for VB6).
 
 
How to run this example:
 
Write the code on a UTF-8 text file as notes.gsb
 
Assign gsb files to open with M2000.exe (the M2000 environment)
 
Open the folder where exist notes.gsb in a cmd window and execute it writing notes.gsb to get the notes.bat. Now you can write notes your note here.
 
 
<syntaxhighlight lang="m2000 interpreter">
MODULE GLOBAL interpret {
global filename$="notes.txt"
declare FreeConsole lib "Kernel32.FreeConsole"
declare GetStdHandle lib "Kernel32.GetStdHandle" {long a}
declare AttachConsole lib "Kernel32.AttachConsole" {long a}
declare CloseHandle lib "Kernel32.CloseHandle" {long a}
declare global WriteCons Lib "Kernel32.WriteConsoleW" {long cons, a$, long n, Long p, long u}
long STD_OUTPUT_HANDLE=-11
global retvalue
buffer clear retvalue as long
ret=AttachConsole(-1)
if ret=0 then beep: exit
global m=GetStdHandle(STD_OUTPUT_HANDLE)
if not islet then
try {
open "notes.bat" for output as #f
print #f, {@}+appdir$+{m2000.exe data {%*}: dir %cd%:load notes
}
close #f
}
PrintConsoleLn("")
dos "notes.bat"
else
read cmd$
cmd$=trim$(cmd$)
if cmd$="" then
if exist(filename$) then
open filename$ for wide input exclusive as #f
while not eof(#f)
line input #f, line$
PrintConsoleLn(line$)
end while
close#
end if
else
if exist(filename$) then
try ok {
open filename$ for wide append exclusive as #f
}
else
try ok {
open filename$ for wide output exclusive as #f
}
end if
if ok then
print #f, str$(now+today,"YYYY-MM-DD hh:mm:ss")
print #f, chr$(9);@RemoveSpaces$(cmd$)
close#f
end if
end if
end if
call void closehandle(m)
call void freeconsole()
Sub PrintConsole(a$)
Call Void WriteCons(m, a$, Len(a$), retvalue(0), 0)
End Sub
Sub PrintConsoleLn(a$)
a$+={
}
Call Void WriteCons(m, a$, Len(a$), retvalue(0), 0)
End Sub
Function RemoveSpaces$(a$)
local b$,c$,i, sk
for i=1 to len(a$)
b$=mid$(a$,i,1)
if sk then
c$+=b$
if b$=""""then
sk=false
b$=mid$(a$,i+1,1)
if b$<>"" and b$<>" " then c$+=" "
end if
else.if mid$(a$,i,2)<>" "then
c$+=b$:if b$=""""then sk=true
end if
next
=c$
End Function
}
module interpret1 {
try {interpret}
}
interpret1: end
</syntaxhighlight>
{{out}}
<pre>
>notes this is "a b" a note.
>notes this is another note.
>notes
2022-11-29 19:32:26
this is "a b" a note
2022-11-29 19:32:45
this is another note.
</pre>
 
 
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
404

edits