I want to comment lines in the ZPL code, for example:
^XA
^MMT
^LL0531
^PW1280
^LS0
^FT81,528^A0B,29,28^FH\^FDTEXT^FS
// ^FT336,495^A0B,29,33^FH\^FDEAN^FS^FX ----
//^BY3,2,42^FT384,492^BEB,,Y,N Commented lines
//^FD789690466123^FS ----
^PQ1,0,1,Y^XZ
I want this because sometimes my variable is null and do not want to print the barcode.
This is possible? or what the best way to not print the barcode?
The short answer is "Can't be done."
The comment-indicator is ^FX after which characters are ignored - but end-of-comment is any ^ or ~ command which makes ^FX next to useless.
Unless there has been a "block-comment" command added, with a specific start/end-block-comment mnemonic-set, then sorry - you're out-of-luck.
All is not quite lost however.
^XA
^FT336,495^A0B,29,33^FH\^FDEAN^FS^FX
^BY3,2,42^FT384,492^BEB,,Y,N
^FD789690466123^FS
^MMT
^LL0531
^PW1280
^LS0
^FT81,528^A0B,29,28^FH\^FDTEXT^FS
^PQ1,0,1,Y^XZ
will recognise the lines-to-be-commented-out.
^FT336,495^A0B,29,33^FH\^FDEAN^FS^FX
^BY3,2,42^FT384,492^BEB,,Y,N
^FD789690466123^FS
^XA
^MMT
^LL0531
^PW1280
^LS0
^FT81,528^A0B,29,28^FH\^FDTEXT^FS
^PQ1,0,1,Y^XZ
would ignore them, as data between ^XZ and ^XA is disregarded.
I build the line to a string variable in code and put my comments in the concatenation - then send that whole string to the printer the comments will stay behind.
StringBuilder sb = New Stringbuilder("");
sb.append("^XA");
sb.appendLine("^MMT");
sb.appendLine("^LL0531");
// sb.append("this line will be commented out");
// sb.append("this line will be commented out");
// sb.append("this line will be commented out");
sb.appendLine("^PQD,0,1,Y^XZ");
string s = sb.toString();
Something like that. You might use an 'if-else' statement instead of comments to determine if it stays in the string.
One way is to not send the command lines related to the fields you do not want to print. For the example you provided, just eliminate (do not send) the three lines starting with //.
#Mangoo
The short answer is "Can't be done."
The comment-indicator is ^FX after which characters are ignored - but end-of-comment is any ^ or ~ command which makes ^FX next to useless.
Not necessarily. I found ^FX to be very useful when commenting out variables to put in test information. In this case, it is actually useful to have end-of-comment triggered by any ^ or ~ command.
With variables as field data.
^XA^PQ1
^FO12,15^A0N,36,33^FDTitle^FS
^FO210,15^A0N,36,33,^FDInfo^FS
^FO750,15^A0N,165,150^FD|Variable.Number|^FS
^FO90,60^BY4,3.0^BCN,90,N,N,Y,N^FD|Variable.Number|^FS
^XZ
With test info and variables commented out.
^XA^PQ1
^FO12,15^A0N,36,33^FDTitle^FS
^FO210,15^A0N,36,33,^FDInfo^FS
^FO750,15^A0N,165,150^FDTestNumber^FX|Variable.Number|^FS
^FO90,60^BY4,3.0^BCN,90,N,N,Y,N^FDTestNumber^FX|Variable.Number|^FS
^XZ
This makes it possible to use test information while adjusting the format and not losing the original variable names. You can also use this to make informational comments like this:
^FX This is a test label.
^XA^PQ1
^FX This is the title.
^FO12,15^A0N,36,33^FDTitle^FS
^FX This is the info.
^FO210,15^A0N,36,33,^FDInfo^FS
^FX This is the number.
^FO750,15^A0N,165,150^FD|Variable.Number|^FS
^FX This is the barcode.
^FO90,60^BY4,3.0^BCN,90,N,N,Y,N^FD|Variable.Number|^FS
^XZ
Related
I've seen these examples for Heredocs in Vagrantfiles:
$myscript1 = <<SCRIPT
echo "test <<"
SCRIPT
$myscript2 = <<-SCRIPT
echo "test <<-"
SCRIPT
$myscript3 = <<~SCRIPT
echo "test <<~"
SCRIPT
Could anyone explain with examples what is the difference between these variants?
Are there more variants for inline Heredocs?
From the heredoc documentation pointed out in the comments:
If you are writing a large block of text you may use a “here document” or “heredoc”:
expected_result = <<HEREDOC
This would contain specially formatted text.
That might span many lines
HEREDOC
The heredoc starts on the line following <<HEREDOC and ends with the next line that starts with HEREDOC. The result includes the ending newline.
You may use any identifier with a heredoc, but all-uppercase identifiers are typically used.
You may indent the ending identifier if you place a “-” after <<:
expected_result = <<-INDENTED_HEREDOC
This would contain specially formatted text.
That might span many lines
INDENTED_HEREDOC
Note that the while the closing identifier may be indented, the content is always treated as if it is flush left. If you indent the content those spaces will appear in the output.
To have indented content as well as an indented closing identifier, you can use a “squiggly” heredoc, which uses a “~” instead of a “-” after <<:
expected_result = <<~SQUIGGLY_HEREDOC
This would contain specially formatted text.
That might span many lines
SQUIGGLY_HEREDOC
The indentation of the least-indented line will be removed from each line of the content. Note that empty lines and lines consisting solely of literal tabs and spaces will be ignored for the purposes of determining indentation, but escaped tabs and spaces are considered non-indentation characters.
I want to use an American flag emoji in my bash prompt (i.e. PS1 environment variable). However, the American flag emoji causes the terminal cursor to offset an extra character to the right.
🇺🇸 is comprised of two unicode characters, 🇺 and 🇸. I believe terminal is converting this to a mono-spaced emoji character (the flag), yet still allocating space for two characters. How can I achieve my expected cursor position?
I want:
🇺🇸 Desktop akirna 🗽 ls|
I get:
🇺🇸 Desktop akirna 🗽 ls | << weird space offset before cursor
My ~/.bash_profile is:
export PS1='🇺🇸 \W \u 🗽 '
Updated Answer
The way your are setting the prompt is not evaluating the escape characters. Add a $ before the string to make it evaluate the escape codes:
pompt$ export PS1='XY \x08: '
XY \x08: echo "Well that didn't work..."
Should become:
pompt$ export PS1=$'XY \x08: '
XY: echo "Escape code success!"
(See Charles Duffy's comment on this answer for why I removed export.)
The example above sets the prompt to the characters X, Y, [space], [backspace], [colon] resulting in a displayed prompt of just "XY:".
On my system, the flag is rendered as two characters (🇺 and 🇸), so I cannot verify this, but I think adding a backspace (\x08) should work for you:
PS1=$'🇺🇸 \\W \\u 🗽\x08'
Notes about edits
My original answer suggested using a sub-shell as follows:
export PS1=$(printf "XY \x08")
Many thanks to Charles Duffy for his input~
I worked around this by converting the character to hex, and then putting zero width markers around the second part of the character
so for 🇺🇸 we get
PS1='\xf0\x9f\x87\xba\[\xf0\x9f\x87\xb8\] '
I am writing a swirl lesson using swirlify package functions in RStudio.
Below is how lesson.yaml file looks like now
- Class: text
Output: Welcome to Part 1 Playing with Numbers!!!
Output for which looks like
How to insert a new line or line break after Welcome to Part 1 in lesson.yaml file above, so that it displays the output as below when I run the demo_lesson() command again after saving the lesson.yaml file
| Welcome to Part 1
| Playing with Numbers!!!
Using YAML, you can use any of these equivalent approaches:
Quoted string with escape
- Class: text
Output: "Welcome to Part 1\nPlaying with Numbers!!!"
Literal scalar
- Class: text
Output: |-
Welcome to Part 1
Playing with Numbers!!!
(| starts a literal scalar and - tells YAML to drop the final line break.)
Multiline scalar
- Class: text
Output:
Welcome to Part 1
Playing with Numbers!!!
(since one line break gets folded into a space, you need two line breaks.)
Since I do not know whether swirlify nicely handles line breaks in the string, I guess you could also do
- Class: text
Output: Welcome to Part 1
- Class: text
Output: Playing with Numbers!!!
Thanks to flyx for answering the question, here is how it works!!
I. Quotes string with escape (Works with two \n\n)
lesson.yaml file
II. Literals
First line in Output: |- Hit ENter once
Indent once by pressing one Tab for first line, Hit Enter twice to have break between header line and paragraph like below, then it works..
lesson.yaml file
III. Mulitline Scalar (Works with three times Enter between two lines)
Press Enter once After Output: in lesson.yaml
Indent once by pressingTab` key once, Write your first line, hit Enter thrice and write the second line. Then it works.
lesson.yaml file
OUTPUT FOR ALL THE ABOVE ANSWERS
The following code is something I am beginning to test for use within a "Texas Hold Em" style game I am working on.
My question is why, when running the following code, does the puts involving a "♥" return a "\u" in it's place. I feel certain it is this multibyte character that is causing the issue becuse on the second puts , I replaced the ♦ with a d in the array of strings and it returned what i was expecting. See Below:
My Code:
#! /usr/bin/env ruby
# encoding: utf-8
table_cards = ["|2♥|", "|8♥|", "|6d|", "|6♣|", "|Q♠|"]
# Array of cards
player_1_face_1 = "8"
player_1_suit_1 = "♦"
# Player 1's face and suit of first card he has
player_1_face_2 = "6"
player_1_suit_2 = "♥"
# Player 1's face and suit of second card he has
test_str_1 = /(\D8\D{2})/.match(table_cards.to_s)
# EX: Searching for match between face values on (player 1's |8♦|) and the |8♥| on the table
test_str_2 = /(\D6\D{2})/.match(table_cards.to_s)
# EX: Searching for match between face values on (player 1's |6♥|) and the |6d| on the table
puts "#{test_str_1}"
puts "#{test_str_2}"
Puts to Screen:
|8\u
|6d|
-- My goal would be to get the first puts to return: |8♥|
I am not so much looking for a solution to this (there may not even be one) but more so a "as simple as possible" explanation of what is causing this issue and why. Thanks ahead of time for any information on what is happening here and how I can tackle the goal.
The "\u" you're seeing is the Unicode string indicator.
For example, Unicode character 'HEAVY BLACK HEART' (U+2764) can be printed as "\u2764".
A friendly Unicode character listing site is http://unicode-table.com/en/sets/
Are you able to launch interactive Ruby in your shell and print a heart like this?
irb
irb> puts "\u2764"
❤
When I run your code in my Ruby, I get the answer you expect:
test_str_1 = /(\D8\D{2})/.match(table_cards.to_s)
=> #<MatchData "|8♥|" 1:"|8♥|">
What happens if you try a regex that is more specific to your cards?
test_str_1 = /(\|8[♥♦♣♠]\|)/.match(table_cards.to_s)
In your example output, you're not seeing the Unicode heart symbol as you want. Instead, your output is printing the "\u" which is the Unicode starter, but then not printing the rest of the expected string which is "2764".
See the comment by the Tin Man that describes encoding for your console. If he's correct, then I expect the more-specific regex will succeed, but still print the wrong output.
See the comment by David Knipe that says it looks like it gets truncated because the regex only matches 4 characters. If he's correct, then I expect the more-specific regex will succeed and also print the right output.
(The rest of this answer is typical for Unix; if you're on Windows, ignore the rest here...)
To show your system language settings, try this in your shell:
echo $LC_ALL
echo $LC_CTYPE
If they are not "UTF-8" or something like that, try this in your shell:
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
Then re-run your code -- be sure to use the same shell.
If this works, and you want to make this permanent, one way is to add these here:
# /etc/environment
LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
Then source that file from your .bashrc or .zshrc or whatever shell startup file you use.
I have a text file:
Function Description
concat Returns the concatenation of the arguments.
contains Returns true if the first argument string contains the second argument string; otherwise returns false.
I'd like to wrap the text on column#2, the result should be:
Function Description
concat Returns the concatenation
of the arguments.
contains Returns true if the first
argument string contains
the second argument
string; otherwise returns
false.
How to do it in vim or shell quickly? Thank you for any suggestions.
The issue can be easily solved in Vim by using the indentexpr option. Set
it to the number of characters designated for the first column,
:set inde=16
then format the text as usual with the gq or gw families of commands.
I don't think this qualifies as "quickly", and I hope someone out there has a better answer, but this is the best I could come up with in vim:
1) Set textwidth to the desired width of your second column:
:set tw=60
2) Mark the first-column words with something special (to be removed later - any non-normal text will do, I'm using jjj here) (using g!/^$/ to ignore empty lines):
:%g!/^$/s/^/jjj/
3) Put the second column text on a separate line:
:%s/ \</ \r/
4) Rewrap all the second-column lines to the desired width:
:%g!/^jjj/normal gqq
5) Join the first line of each second-column paragraph with its first-column word (should preserve the space that was after the first-column words at the beginning):
:%g/^jjj/join
6) Indent all the remaining second-column lines the appropriate amount to line them up (use however many >>s are needed - there may be a way to make vim check the length of the last first-column line and insert that number of spaces instead of using this method):
:%g!/^jjj/normal >>>>>>>>
7) Finally remove the first-column marker from the first columns:
:%s/^jjj//
Not worth it for your example, but if the file's large enough, it's better than doing it by hand...
:set tw=80 #or :set textwidth=80
Would wrap text to 80 chars.
Then you can type in command mode:
gg #go to the top
and then
gqG #apply reformat to the end
Reference:
http://www.cs.swarthmore.edu/help/vim/reformatting.html