wxTextEntryDialog converts '\n' into '\\n'
This code
dc.DrawText( "line a\nline b", 10, 100 );
outputs what I expect
line a
line b
So I code this:
wxTextEntryDialog dlg(this,"","Name the flower");
dlg.ShowModal();
setName( dlg.GetValue().wc_str() );
dc->DrawText( getName(), 10, 10 );
and type in
line a\nline b
and the display shows
line a\nline b
Using wxWidgets v3.0.1 on Windows
The drawing sample shows that DrawText() does work with multiple lines, so something must be wrong with your code. I can't say what though as you don't show us much, the snippet you do show wouldn't even compile because the arguments order is wrong, so clearly you must be doing something different in your real program.
The workaround is to add
wxString name = getName();
name.Replace("\\n","\n");
dc->DrawText( name, 10, 10 );
Full source code for demo app at https://www.dropbox.com/s/l6wu7pxtwvcj9vp/so26003871.zip?dl=0
Related
I enjoy using the REPL in intelliJ for coding problems like you would find on codesignal. I currently have the version:
IntelliJ IDEA 2019.1.3 (Ultimate Edition)
Build #IU-191.7479.19, built on May 27, 2019
JRE: 1.8.0_202-release-1483-b58 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.4
I have always been really confused by the fact that when running any of these scratch files, the first 5-9 lines I am trying to print output to will just, not exist.
Below is an example program that would print out a pyramid of X's to the console
fun createPyramid(height: Int, drawChar: String = "X") {
// repeat(9) {
// println("blank")
// }
for (i in 1 until height) {
val blank = " ".repeat(height - i)
val row = blank + drawChar.repeat(i * 2 - 1)
println(row)
}
}
createPyramid(11)
If I have the repeat block commented out, my output looks like:
If I uncomment the repeat I will then get output looking like:
The really confusing part about this situation is the number of lines seem to be random, and there is inconsistencies in how it works.
If I do repeat(9) I normally get 1 actually printed out "blank"
If I do repeat(8) most of the time it will actually not put out the first expected "X" from the pyramid.
Output for scratches is printed right in the editor, next to the expression, that provide this output. Scratch Output tool window prints only the output that doesn’t fit into the editor.
Inside my C-program, I need to run the following pragma command:
const char *sql = "PRAGMA table_info(family)"; /* 'family' is the table name */
But whether i try to run this sql via sqlite3_exec() routine or sqlite3_prepare_v2() routine, my program stops responding/working at Windows command-prompt (it's a simple 'console program' in c-language).
Interestingly, when i run that same pragma sql at command-prompt normally by running the sqlite3.exe itself, it runs just fine and gives following output:
sqlite> pragma table_info(family);
cid name type notnull dflt_value pk
---------- ---------- ---------- ---------- ---------- ----------
0 id INTEGER 0 1
1 name TEXT 1 0
2 nickname TEXT 1 0
3 dob TEXT 1 CURRENT_TI 0
But inside my own c-program it doesn't. I have done a bit research about this problem. Both Googling and SQLite Documentation point towards this page here at the official docs. But unfortunately the given information there hasn't enabled me enough to resolve the problem. How can we successfully run SQLite3 'PRAGMA' commands via C-API?
EDIT: Here are the actual problematic lines of code. OR MCVE
I have found the reasons of my program's failure, and have fixed it (Courtesy of clues and leads in Murphy's answer. But for those interested in reproducing the problem, here are the actual lines of code which were causing program to "crash".
Inside my callback function for sqlite3_exec() routine, I had this piece of code(for-loop) for printing ' ---------- ' characters below column names to mimic ".mode column" & ".headers on" style of output in sqlite3 console.
int h;
for(h=0; h <= (strlen(col_value[i])+5); h++)
printf("-");
The problem was being caused by strlen() while printing 'headers' for PRAGMA sql's result column dflt_value which is null for first three columns in my table. If i stop running strlen() on dflt_value. the program runs fine. Similarly, in sqlite3_prepare_v2() routine the problem was being caused by the following lines:
int h;
for(h=0; h <= (strlen(sqlite3_column_text(stmt, 4))+5); h++)
printf("-");
If i remove or comment these lines, all runs well - albeit without ".headers on" style.
sqlite3_exec() should indeed be the way to go to execute pragma commands. You didn't give a MCVE (shame on you!), but I suspect that you either neglect handling error values, or something else is wrong with your code. You should try debugging it.
I would like to knit the output of my R-markdown, which includes a couple of SQL-chunks. However, if I start knitting, I get the error:
Line 65 Error in eval(expr, envir, enclos) : object 'pp_dataset' not found Calls: <Anonymous> ... process_group.block -> call_block -> eval_lang -> eval Execution halted
I have no clue what is going on, because if I just run this chunk (which starts at line 64) then it works fine.
The chunk that starts at line 64 looks as follows:
```{sql, connection=con, output.var=pp_dataset, error=TRUE, echo=FALSE, include=TRUE}
SELECT
(...)
order by 1,2
```
I've tried several knit-options like error=TRUE/FALSE, echo=TRUE/FALSE and include=TRUE/FALSE but that doesn't work.
Anyone a clue what's wrong?
It looks like you need to quote the dataset name in the rchunk options:
```{sql, connection=con, output.var="pp_dataset", error=TRUE, echo=FALSE,
include=TRUE}
SELECT
(...)
order by 1,2
```
Source: http://rmarkdown.rstudio.com/authoring_knitr_engines.html#sql
I answered the question in this post as well. I'm not sure as to the protocol as the answers are identical.
When rendering your document, Rmarkdown does not have access to your global environment. So you should make sure that all variables that you want to use are defined within the Rmarkdown document, e.g. in a initial chunk:
```{r setup, include=FALSE, warning=FALSE, message=FALSE}
(...)
```
or you should type
render("yourfile.Rmd")
instead of pressing the knit button. In that case, the document does have access to your global environment variables. In this case I guess the 'con' connection is in your global environment, and not found while rendering. Hope this helps!
EDIT: I was able to reproduce the error with your example code:
I was not able to run your code without first initializing the output variable of the SQL statement. In your top-chunck ( so for example below the line setwd(mydirectory), try:
pp_dataset <- NULL
Hope this also solves the issue for you.
I built a OS X command line tool in Swift (same problem in Objective-C) for downloading certain files. I am trying to update the command line with download progress. Unfortunately, I cannot prevent the print statement to jump to the next line.
According to my research, the carriage return \r should jump to the beginning of the same line (while \n would insert a new line).
All tests have been performed in the OS X Terminal app, not the Xcode console.
let logString = String(format: "%2i%% %.2fM \r", percentage, megaBytes)
print(logString)
Still, the display inserts a new line. How to prevent this?
Note: This won't work in Xcode's debugger window because it's not a real terminal emulator and doesn't fully support escape sequences. So, to test things, you have to compile it and then manually run it in a Terminal window.
\r should work to move to the beginning of the current line in most terminals, but you should also take a look at VT100 Terminal Control Escape Sequences. They work by sending an escape character, \u{1B} in Swift, and then a command. (Warning: they make some pretty ugly string definitions)
One that you'll probably need is \u{1B}[K which clears the line from the current cursor position to the end. If you don't do this and your progress output varies in length at all, you'll get artifacts left over from previous print statements.
Some other useful ones are:
Move to any (x, y) position: \u{1B}[\(y);\(x)H Note: x and y are Ints inserted with string interpolation.
Save cursor state and position: \u{1B}7
Restore cursor state and position: \u{1B}8
Clear screen: \u{1B}[2J
You can also do interesting things like set text foreground and background colors.
If for some reason you can't get \r to work, you could work around it by saving the cursor state/position just before you print your logString and then restoring it after:
let logString = String(format: "\u{1B}7%2i%% %.2fM \u{1B}8", percentage, megaBytes)
print(logString)
Or by moving to a pre-defined (x, y) position, before printing it:
let x = 0
let y = 1 // Rows typically start at 1 not 0, but it depends on the terminal and shell
let logString = String(format: "\u{1B}[\(y);\(x)H%2i%% %.2fM ", percentage, megaBytes)
print(logString)
Here's an example assuming some async task is taking place with callbacks that pass a Progress type.
// Print an empty string first otherwise whichever line is above the printed out progress will be removed
print("")
let someProgressCallback: ExampleAsyncCallbackType = { progress in
let percentage = Int(progress.fractionCompleted * 100)
print("\u{1B}[1A\u{1B}[KDownloaded: \(percentage)%")
}
The key part is \u{1B}[1A\u{1B}[K and then whatever you want to print out to the screen following.
Your example will only work on the actual command line, not in the debugger console. And you also need to flush stdout for every iteration, like this:
var logString = String(format: "%2i%% %.2fM \r", 10, 5)
print(logString)
fflush(__stdoutp)
I'm having a bit of trouble with building a Dist::Zilla distribution. Every time I try and build it, or really do anything (i.e., test, smoke, listdeps, whatever it is), I get this error message:
Attribute name must be provided before calling reader at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/MooseX/LazyRequire/Meta/Attribute/Trait/LazyRequire.pm line 40
MooseX::LazyRequire::Meta::Attribute::Trait::LazyRequire::__ANON__('Dist::Zilla::Dist::Builder=HASH(0x53d06e0)') called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/x86_64-linux/Class/MOP/Mixin/AttributeCore.pm line 45
Class::MOP::Mixin::AttributeCore::default('Moose::Meta::Class::__ANON__::SERIAL::5=HASH(0x50c9c30)', 'Dist::Zilla::Dist::Builder=HASH(0x53d06e0)') called at reader Dist::Zilla::name (defined at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Dist/Zilla.pm line 41) line 6
Dist::Zilla::name('Dist::Zilla::Dist::Builder=HASH(0x53d06e0)') called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Dist/Zilla/Dist/Builder.pm line 264
Dist::Zilla::Dist::Builder::build_in('Dist::Zilla::Dist::Builder=HASH(0x53d06e0)', undef) called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Dist/Zilla/Dist/Builder.pm line 315
Dist::Zilla::Dist::Builder::ensure_built_in('Dist::Zilla::Dist::Builder=HASH(0x53d06e0)') called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Dist/Zilla/Dist/Builder.pm line 304
Dist::Zilla::Dist::Builder::ensure_built('Dist::Zilla::Dist::Builder=HASH(0x53d06e0)') called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Dist/Zilla/Dist/Builder.pm line 322
Dist::Zilla::Dist::Builder::build_archive('Dist::Zilla::Dist::Builder=HASH(0x53d06e0)') called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/Dist/Zilla/App/Command/build.pm line 30
Dist::Zilla::App::Command::build::execute('Dist::Zilla::App::Command::build=HASH(0x4aeb7b0)', 'Getopt::Long::Descriptive::Opts::__OPT__::2=HASH(0x4bdb150)', 'ARRAY(0x3873fc8)') called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/App/Cmd.pm line 231
App::Cmd::execute_command('Dist::Zilla::App=HASH(0x3c6f418)', 'Dist::Zilla::App::Command::build=HASH(0x4aeb7b0)', 'Getopt::Long::Descriptive::Opts::__OPT__::2=HASH(0x4bdb150)') called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/lib/site_perl/5.14.0/App/Cmd.pm line 170
App::Cmd::run('Dist::Zilla::App') called at /home/mxe/perl5/perlbrew/perls/perl-5.14.0/bin/dzil line 15
Or something along those lines. The contents of my dist.ini are as follows:
author = Gary Warman <email#host.com>
license = None ; this is an all rights reserved license
copyright_holder = Gary Warman
copyright_year = 2011
[ReadmeFromPod]
[#Filter]
-bundle = #Basic
-remove = Readme
[AutoPrereqs]
[OurPkgVersion] ; use this instead of [PkgVersion]
[PodWeaver]
[MetaNoIndex]
file = perlcritic.rc
[MetaJSON]
[NextRelease]
format = %-9v %{yyyy-MM-dd}d ; make Changes Spec happy
[#TestingMania]
disable = NoTabsTests ; TestSynopsis optional if synopsis is not perl or if it's a largely generated codebase
critic_config = perlcritic.rc
[ExtraTests]
[PodSpellingTests]
wordlist = Pod::Wordlist::hanekomu ;optional
spell_cmd = aspell list
[PruneFiles]
filenames = dist.ini
filenames = weaver.ini
[#Git]
[Git::NextVersion]
first_version = 0.1.0 ; use semantic versioning if you don't know what this means read: http://semver.org/ may switch to the semantic versioning plugin at some point.
[CheckChangesHasContent]
[Clean] ; optional, this cleans up directories upon running dzil release.
So, anyone here have any idea what's going on so I can resolve this?
Your dist.ini file must contain an assignment for name, which is what that horrid error is reporting. Insert, at the very very top of your file:
name = My-Awesome-Dist
...and it will work.