I would like to turn off word wrap in my vscode terminal so I can more easily view compiler messages.
e.g.
Imagine this is a very long line generated from a compiler and it has a lot of information and when it word wraps it is very hard to read so I would like vs code to just have a scroll bar at the bottom like SO has here.
However, after attempting several different methods of disabling word wrap, what is actually generated looks like:
Imagine this is a very long line generated from a compiler and it
t has a lot of information and when it word wraps it is very hard to read so I would like vs code to just have a scroll bar at the bottom like SO has here.
(extra t on the second line is intentional)
So it appears that I've managed to turn off word wrap internal to vscode, but something is still causing a carriage return (with no line feed), I think?
These messages are produced by running a C++ build task in the integrated terminal that in turn calls cmd.exe to run a script (e.g. cmd.exe <build command script>
Here is what I've tried so far:
First thing I tried was turning off word wrap in vscode (alt + z, or View > Word Wrap). This led to the weird line break described above.
I was suspicious that cmd was the one causing this weird line break, so I disabled "wrap text output on resize" and set the screen buffer width manually to 1000 (1000 >> greater than any of my output lines) within
command prompt properties for both "properties" and "default". I then tested the same command running in my vscode terminal and it worked as expected in the cmd terminal but still not vscode.
I was suspicious powershell (which I think vs code uses in it's integrated terminal?) was the one causing the line break, so I set the properties the same as in the cmd image above. Again this worked as expected in the powershell terminal, but still not vscode.
Following this, I changed the "terminal fixed dimensions" using the command from the command pallet and set the width to a matching column width of 1000 (leaving row empty for "automatic").
I've tried restarting vscode and my pc between several of these steps with no change.
What could be causing this behavior inside of the vscode terminal?
Does a VS code have a core command to write to the Output section?
For instance, there are the commands cursorLeftSelect, editor.action.clipboardCutAction, cursorRight, editor.action.clipboardPasteAction, and, of course, the type command to type. Is there a command to write to output?
Yes, look at the window.createOutputChannel("find-and-transform"); command. You can put anything you want where the find-and-transform appears above.
yourOutputChannel.appendLine(`\n${ jsOPError.stack }\n`);
yourOutputChannel.show(false); // the false here will focus the output panel and this outputChannel within it
I am coding python using VS code.
However, all the codes I wrote are printed out on the terminal. And then you get the printed value.
For example, When I write 1+3, I only want see 4 but the terminal show me 1+3 and 4.
I hope only the printed value come out on the terminal.
I don't know what's wrong with the setting and it's coming out like this.
enter image description here
I am coding python using VS code.
However, all the codes I wrote are printed out on the terminal. And then you get the printed value.
For example, When I write 1+3, I only want see 4 but the terminal show me 1+3 and 4.
I hope only the printed value come out on the terminal.
I don't know what's wrong with the setting and it's coming out like this.
>>> print("Hello")
Hello
>>> print("Hello")
Hello
>>> 1+3
4
>>> 2+8
10
>>>
Looking at your picture, you're entering '1+3' into the terminal, correct? That's why you're seeing 1+3 followed by 4. The 1+3 in the terminal (as well as the 'print("Hello")') are what you've typed in. If you only want to see the output of your code in the terminal, you need to run the python script directly using the 'python3' command.
In your chapter1 > testt.py file, you have:
print("Hello")
1+3
2+8
Try updating this to look like:
print("Hello")
print(1+3)
print(2+8)
and save your file.
Then, in the terminal, type:
python3 testt.py
This command actually runs the script. Then you'll see the output from the scrip (the print statements), and you should see:
Hello
4
10
The distinction between the terminal and what it displays and the actual results of your code can be confusing when first starting programming. Good luck!
I came across some strange behaviors of StdIn.readLine in Scala. Here's the code excerpt:
while (true) {
print("prompt:>")
var lbl = ""
lbl = scala.io.StdIn.readLine()
println("echo" + lbl)
}
Strangely, when running, the readLine() happens before printing out the "prompt:>".
I have:
fork in run := true
connectInput in run := true
in my build.sbt
Anyone knows what's happening?
The output is line buffered. You need to System.out.flush after printing the prompt to make it show up in the console. Otherwise, it waits for the buffer to fill (or a new line to appear in the output).
Writing to files (and the terminal is considered one) is costly, so for performance reasons the standard output is buffered. This means that the write will actually only occur once the buffer becomes full, or once a line return gets put into the buffer. You can force the buffer to flush using System.out.flush.
For your problem however, you might want to use scala.io.StdIn.readLine("prompt:>") directly: it's made exactly for what you're trying to do.
I had this problem when running codes in the console, i.e Ctrl+shift+X on a piece of code in IntelliJ to have them run in the console. I added those line you indicated in the build.sbt and for feeding in the input into the console I use Ctrl+Enter after typing the input. Just for your info, my Scala code is:
import scala.io.StdIn.{readLine}
val input = readLine("enter some word ")
println(s"the word is $input ")
I just wrote my first extensive Python tutorial using IPython notebooks. All went well, except I did a lot of testing and moving blocks around. How do I reset the In [ ]: numbering? I have tried quitting and reloading, but that doesn't seem to work.
I think, the only way to to what you want is:
- 'Kernel > Restart' (restart the kernel) and then 'Cell > Run All' (run the script).
Every .ipynb file can be opened in an editor. Everything written there is in plain text (JSON). For each cell which has the "cell_type": "code" there'd be another key-value pair as "execution_count": <number>. As you might have guessed, that is the prompt numbering. Hence, if the notebook contains code which will take time to execute (as was, in my case) this method would be time efficient.
Now, either you can manually change each execution_count or write a simple script to get the numbering right. To check the results just refresh the notebook in the browser without stopping the kernel. And, everything will be as per your needs, even all the variables/loaded data will remain in the environment.
You can reset the kernel (shortcut: C-m .) and re-run the whole notebook.
Quitting and reloading doesn't work because the code is not re-evaluated.
'Kernel' -> 'Restart & Run All'
Just make sure you saved your Notebook. You can also bind/assign keyboard key for running this command.
'Help' -> 'Edit Keyboard Shortcuts'
If what you want is to remove the numbers themselves, so that each cell shows In [ ] (instead of something like In [247] which is leftover from some previous incarnation of the kernel), use "Cell" > "All Output" > "Clear" (in Jupyter Notebook 5.4.0) or "Edit" > "Clear All Outputs" (In Jupyter Lab 0.32.1).
This will remove all the numbers, even if you're in the middle of running a notebook. It will not reset the numbering back to 1; e.g. if the last cell you executed was 18, the next will be 19.
If you're using this because you want clarity about which cells you've executed during this run of the kernel and which cells you haven't executed yet, use "Cell" > "All Output" > "Clear" (or "Edit" > "Clear All Outputs") immediately after you start (or restart) the kernel. This can be useful when restarting a kernel, or when opening a saved or duplicated notebook.
This will also remove all outputs from the notebook.
Thanks to user2651084 in a previous comment for this.
I'm a bit too late, but I had the same problem, and since my notebook had cells with execution time up to 5 minutes, I had to wait a long time until Restart & Run All finished.
So I've made a Python script to make this task for me:
import json
file = '/your/notebook/path/Notebook.ipynb'
# Since every notebook is actually a JSON (JavaScript
# Object Notation), then its contents can be represented
# in a dictionary (or a list of dictionaries)
with open(file, encoding='utf-8') as f:
nb = json.load(f)
count = 1
for cell in nb['cells']:
# Markdown cells doesn't have execution count,
# so apply this only to cells that have one
if 'execution_count' in cell:
cell['execution_count'] = count
count += 1
# Not all code cells have output, such as functions
# that return None or simple declarations, so apply
# this only to cells that have some output
try:
for output in cell['outputs']:
if 'execution_count' in output:
output['execution_count'] = cell['execution_count']
except KeyError:
continue
with open(file, 'w+') as f:
json.dump(nb, f, indent=2, ensure_ascii=False)
But be careful with the execution order and the variables in your cells, since applying the script above on your notebook can generate a different output if you run the notebook again. For example, let's suppose your notebook have the following cells with the execution order in square brackets:
In [2]: a = 1
In [1]: a = 2
In [3]: a
Out[3]: 1
If you apply the above script into your notebook, it'll show the following:
In [1]: a = 1
In [2]: a = 2
In [3]: a
Out[3]: 1
But if you run the notebook again, it'll show the following:
In [1]: a = 1
In [2]: a = 2
In [3]: a
Out[3]: 2
This can be a bit confusing for people who are downloading your notebook via GitHub for example, since they can see an output in the repository, but when they run on their machine, the output will be different.
Cell > All Output > Clear Clear all In []: numbers but do not reset them back to 1 for the next cell you run.
Kernel > Restart & Clear Output Restart the kernel, clear output, clear In []: numbers and reset them to 1, and clear output.
Restart & Run All isn't a good solution, because simply I don't want to run all (and that's the purpose of a notebook to run things cell by cell).
Anyways, I found this solution more plausible:
Main Menu > Cell > All Output > Clear
For those coming from Google:
%reset
This is useful when you want to reset all variables after a certain point in the notebook. It is going to ask if you are sure that you want to reset. If you want to force reset without asking, then use:
%reset -f
Here is how to clear the execution numbers to [ ] without re-running the whole notebook:
Just to be safe, make a copy of your notebook:
cp notebook.ipynb notebook_copy.ipynb
Open your notebook with vim:
vim notebook.ipynb
In vim, reset the execution numbers with the following search-replace command:
:%s/"execution_count":.*/"execution_count": null,/gc
You will then get the following prompt. Type a to replace all occurrences:
replace with "execution_count": null, (y/n/a/q/l/^E/^Y)? a
Save notebook and quit vim:
:wq