terminal

How curses preserves screen contents?

假如想象 提交于 2019-12-12 12:49:47
问题 When you start the (n)curses program, it will remove the scroll bar from your terminal emulator, clear the screen, the scroll log (history) will also disappear. When you exit the program, the screen contents reappears, the scroll bar returns, and the scroll buffer returns. How ncurses does it? I have studied all ANSI escape codes, I cannot see anything that can do such things. What is the technology behind this? 回答1: This is discussed at length in the xterm FAQ Why doesn't the screen clear

Term::Readline: encoding-question

无人久伴 提交于 2019-12-12 12:24:22
问题 When I enter "Müller", on the screen appears "M??ller". How could I fix this? #!/usr/bin/env perl use warnings; use 5.012; use Term::ReadLine; my $term = Term::ReadLine->new( 'dummy' ); my $con = $term->readline( ': ' ); say $con; # On the screen: # : M��ller # Müller 回答1: Apply :utf8 layer to filehandles STDIN and STDOUT , and pass them as arguments to Term::ReadLine->new() : binmode STDIN, ':utf8'; binmode STDOUT, ':utf8'; my $term = Term::ReadLine->new( 'dummy', \*STDIN, \*STDOUT ); 来源:

Custom failure messages in Rspec

谁说我不能喝 提交于 2019-12-12 12:22:34
问题 In my RSpec + Capybara tests, when I'm expecting something but the test fails, I'd like to have some custom messages. I achieved it with: it "a test" do do_something expect(current_path).to eq('/some/path'), "expected path to be 'some_path' but fails" end but what I'd like to have is ONLY my custome message, without the Failure/Error line from RSpec Is this possible? 回答1: If you want to customize the ouput, you should write a custom formatter. Base example: class MyFormatter RSpec::Core:

How can I reorganize nested quotes within sed regex in a bash script that triggers an “unterminated substitute pattern” error?

纵饮孤独 提交于 2019-12-12 11:18:37
问题 The following command is throwing an unterminated substitute pattern error in bash: eval $(echo "sed '" "s,@\("{a..u}{a..z}"\),\n\n\1,;" "'") But not for everyone. Linux apparently works fine. Mac throws the unterminated substitute pattern error. How can I reorganize to make this work? Here's the entire bash command (the goal is to cleanly output current MySQL settings into my.cnf) : { # Print version, user, host and time echo -e "# MYSQL VARIABLES {{{1\n##\n# MYSQL ` mysql -V | sed 's,^.*\(V

How can I tell (in script) how many Terminals are open in mac os x?

痴心易碎 提交于 2019-12-12 11:17:53
问题 how can I tell how many Terminal windows (in mac os x) are currently opened? this needs to be done from a shell script. thanks, 回答1: This script does what you ask for, you use osascript to run it from the cmd line. tell application "Terminal" set c to 0 repeat with i from 1 to (count of windows) set c to c + (count of tabs in window i) end repeat c end tell Edit by Bavarious: In order to use Adam’s AppleScript inside a shell script, you can do the following: #!/bin/bash read -d '' OSASCRIPT <

Mac -bash: node: command not found

。_饼干妹妹 提交于 2019-12-12 11:03:21
问题 I am having problems running node.js from the terminal. I have run the node.js installer for mac, but when I try to use the node command in the terminal, I get the following error: -bash: node: command not found I have been trying to look for a solution but all the suggestions I found, dont help In the folder /usr/local/bin I have node and npm, but even when I navigate to the folder and run node, I still get the same error. I don't understand why this is happening, because I can see that node

Find out if a python script is running in IDLE or terminal/command prompt

强颜欢笑 提交于 2019-12-12 10:49:07
问题 Is there a way to find out if the python script is running in the IDLE interpreter or the terminal? Works cross-platform if possible, or if needed a different way for each platform. Work with Python 2 and Python 3 if possible, or if needed a different way for each version. The only way I could think of is checking the processes running for IDLE but I don't know how to do that right. If IDLE is open for another script and my script is running in the terminal, a process check would return true

C/C++ : Can I keep the cursor in the current line after pressing ENTER?

百般思念 提交于 2019-12-12 10:48:23
问题 I would like to ask if there's any way to keep the cursor in the current line after pressing ENTER !! for example ... #include<stdio.h> int main() { int d=0; printf("Enter a number : "); scanf("%d",&d); if(d%2)printf(" is a Odd number\n"); else printf(" is a Even number\n"); return 0; } An example of output : Enter a number : 10 is a Even number ... but what I need is something like that : Enter a number : 10 is a Even number I want to put "is a Even number" (or " is a Odd number") next to

npm install -g mongodb not installing mongodb globally on OSX 10.8.4?

老子叫甜甜 提交于 2019-12-12 10:45:27
问题 I know similar questions have been asked to death, but I can't find my particular situation. I'm just trying to install mongodb globally so that I may run it from any directory by typing mongod instead of being in the specific bin and typing ./mongod which works. I get this error when trying: Squirrels-MacBook-Air:Code Squirrel$ npm install -g mongodb npm http GET https://registry.npmjs.org/mongodb npm http 304 https://registry.npmjs.org/mongodb npm ERR! Error: EACCES, mkdir '/usr/local/lib

How to access your terminal window via the browser?

坚强是说给别人听的谎言 提交于 2019-12-12 10:19:25
问题 I want to access my ubuntu terminal using my browser i found a npm package web-terminal but it is kind off not complete. I have seen jupyter notebook do it. so is there a solution for it or a way to get that terminal thingy out of jupyter notebook. Example: Just like when u access your google cloud server via your browser with some sort of shell. Note: I didn't get anything to start with just the npm web-terminal so i won't be able to show much effort from my side. Thank you in advance. :D