NodeJS - 커맨드 라인의 검은 화면을 유지하고 계산기를 사용하고 싶습니다. . . 라는 것으로 만들어 보았다. cli 계산기.
tl;dr
계산기를 하나씩 시작하는 것도,
커맨드 라인으로 완결시키고 싶다.
라는 생각에서 cli 계산기를 nodejs로 만들어 보았습니다.
(깨달으면, 구구루보다 빨리 손이 움직이고 있었습니다. 누군가 만들고 있다고 생각합니다만, 굳이.)
만들어 보자.
index.jslet readlineSync = require("readline-sync");
let math = require("mathjs");
let variables = {};
let flagFinish = false;
do{
process.stdout.write("\u001b[36m数式を入力\u001b[0m\n = ");
let input = readlineSync.question();
if(input.startsWith(">$")){
let variableName = input.slice(1)
variables[variableName] = variables.$ans;
process.stdout.write(` \x1b[4m${variableName} に $ans (${variables.$ans}) が保存されました。\u001b[0m\n`);
}else if(input.startsWith(">exit")){
flagFinish = true;
}else{
let ans = math.eval(input, variables);
if(ans){
process.stdout.write(` ans: \x1b[4m\x1b[35m${ans}\u001b[0m\n`);
variables.$ans = ans;
}
}
process.stdout.write("\n");
}while(!flagFinish);
명령줄에서 다음을 입력합니다.
npm install readline-sync
npm install mathjs
...バーーーーーーーっとなんか出る。
이것만! ! ! ?
사용법!
수식 입력

코드
1 + 1 // -> 2
2018 - 2020 // -> -2
100 * 200 // -> 20000
20 / 3 // -> 6.666666666666667
8 ^ 3 // -> 512
4! // -> 24
수식에 관해서는 보통 사칙 연산은 물론 그 외 여러 가지를 입력하기만 하면 됩니다.
완전히 math.js 사양에 따라 다릅니다.
마지막 계산 결과 사용

코드
= 10!
ans: 3628800
= $ans
ans: 3628800
마지막 계산 결과는 $ans
에 저장됩니다.
계산 결과를 메모리에 저장합니다.

코드
数式を入力
= sqrt(2)
ans: 1.4142135623730951
数式を入力
= $ans
ans: 1.4142135623730951
数式を入力
= >$memory
$memory に $ans (1.4142135623730951) が保存されました。
数式を入力
= sqrt(3)
ans: 1.7320508075688772
数式を入力
= $ans
ans: 1.7320508075688772
数式を入力
= $memory
ans: 1.4142135623730951
끝내다

코드
数式を入力
= >exit
>exit
를 입력하십시오.
(잡잡이 때문에 공간이 >
와 exit
사이에 들어가면 움직이지 않습니다.)
마지막으로
버그 수정 등은 하지 않으므로 양해 바랍니다.
기능 추가 등은 코멘트 부탁드립니다.
(시간이 있을 때나, 마음이 돌았을 때에 고쳐줍니다.
)
Reference
이 문제에 관하여(NodeJS - 커맨드 라인의 검은 화면을 유지하고 계산기를 사용하고 싶습니다. . . 라는 것으로 만들어 보았다. cli 계산기.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/lemon2003/items/4bb4492ac80a94cc7bcb
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
let readlineSync = require("readline-sync");
let math = require("mathjs");
let variables = {};
let flagFinish = false;
do{
process.stdout.write("\u001b[36m数式を入力\u001b[0m\n = ");
let input = readlineSync.question();
if(input.startsWith(">$")){
let variableName = input.slice(1)
variables[variableName] = variables.$ans;
process.stdout.write(` \x1b[4m${variableName} に $ans (${variables.$ans}) が保存されました。\u001b[0m\n`);
}else if(input.startsWith(">exit")){
flagFinish = true;
}else{
let ans = math.eval(input, variables);
if(ans){
process.stdout.write(` ans: \x1b[4m\x1b[35m${ans}\u001b[0m\n`);
variables.$ans = ans;
}
}
process.stdout.write("\n");
}while(!flagFinish);
npm install readline-sync
npm install mathjs
...バーーーーーーーっとなんか出る。
1 + 1 // -> 2
2018 - 2020 // -> -2
100 * 200 // -> 20000
20 / 3 // -> 6.666666666666667
8 ^ 3 // -> 512
4! // -> 24
= 10!
ans: 3628800
= $ans
ans: 3628800
数式を入力
= sqrt(2)
ans: 1.4142135623730951
数式を入力
= $ans
ans: 1.4142135623730951
数式を入力
= >$memory
$memory に $ans (1.4142135623730951) が保存されました。
数式を入力
= sqrt(3)
ans: 1.7320508075688772
数式を入力
= $ans
ans: 1.7320508075688772
数式を入力
= $memory
ans: 1.4142135623730951
数式を入力
= >exit
버그 수정 등은 하지 않으므로 양해 바랍니다.
기능 추가 등은 코멘트 부탁드립니다.
(시간이 있을 때나, 마음이 돌았을 때에 고쳐줍니다.


Reference
이 문제에 관하여(NodeJS - 커맨드 라인의 검은 화면을 유지하고 계산기를 사용하고 싶습니다. . . 라는 것으로 만들어 보았다. cli 계산기.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/lemon2003/items/4bb4492ac80a94cc7bcb텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)