center text in a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

center text in a batch file

#1 Post by batchcc » 03 Sep 2015 05:21

I have an image of some text i randomized it because it was confidential but i converted it on text-image.com and added it to a text file and added about 7 tabs in front of it ( in notepad++ just select all and hit tab ) but this changes the formatting when a batch file uses the type command to type it what can i do here is the text

Code: Select all

:ooooooo-      +oooooooo:oooooooooooooo/:`    :oooooo:        .oooooooo..oooooooooooooo/-     
      `:yMMMMh`      `-oMMMMo-``-dMMMd:.`-+mMMMN:   ``+NMMMMy.       .hMMMMh.  `-dMMMd:../yMMMMm`   
         sMMMMo         MMN:     +MMMs      dMMMd      dNNMMMm/       `mMMd`     +MMMs    `sMMMM+   
          dMMMN-       +MM:      +MMMs      -MMMs      dd.hMMMMh`      +MM+      +MMMs      MMMM-   
          .mMMMm      .NM+       +MMMs      oMNo       dd  /NMMMN/     -MM.      +MMMs     `MMN/   
           :MMMMs     hMy        +MMMd++++ohmo.        dd   .yMMMMd-    MM       +MMMNo:` :dNs`     
            sMMMN:   sMh         +MMMy---/odMMNds-     dd     /dMMMMo`  MM       +MMMNMMMMN/       
            `hMMMm  /Nm`         +MMMs      -dMMMm     dd      `sMMMMd- MM       +MMMs:NMMMm.       
             .NMMMs-NN.          +MMMs       .MMMM    -MN.       -mMMMNsMM       +MMMs .dMMMN/     
              +MMMNNN:           +MMMs       `MMMs    +MM/        `oNMMMMM       +MMMs  `oMMMMs`   
               sMMMM+            +MMMy      `yMN+`   `mMMd`         -dMMMM       +MMMy    /NMMMd/   
               `mMMs          `:omMMMMds+//shh/`    +dMMMMd/         `oNMM    `:omMMMMs/.  .dMMMMmo-
                .o/           `:::::::::::-`        ::::::::           .yy    `:::::::::.    .:::::.
                                                                                                   

the text will appear as vbnr if you type
@echo off
cls
mode 1000
type vbnr.txt
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: center text in a batch file

#2 Post by foxidrive » 03 Sep 2015 06:57

One issue is that fonts in a cmd window can be changed by the user
and you will only see the text correctly in a mono-spaced font.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: center text in a batch file

#3 Post by foxidrive » 03 Sep 2015 07:05

Just for laughs, try this:

Code: Select all

@echo off
mode 1000
:loop
set "#001=%spc%        :ooooooo-      +oooooooo:oooooooooooooo/:`    :oooooo:        .oooooooo..oooooooooooooo/-"
set "#002=%spc%      `:yMMMMh`      `-oMMMMo-``-dMMMd:.`-+mMMMN:   ``+NMMMMy.       .hMMMMh.  `-dMMMd:../yMMMMm`"
set "#003=%spc%         sMMMMo         MMN:     +MMMs      dMMMd      dNNMMMm/       `mMMd`     +MMMs    `sMMMM+"
set "#004=%spc%          dMMMN-       +MM:      +MMMs      -MMMs      dd.hMMMMh`      +MM+      +MMMs      MMMM-"
set "#005=%spc%          .mMMMm      .NM+       +MMMs      oMNo       dd  /NMMMN/     -MM.      +MMMs     `MMN/"
set "#006=%spc%           :MMMMs     hMy        +MMMd++++ohmo.        dd   .yMMMMd-    MM       +MMMNo:` :dNs`"
set "#007=%spc%            sMMMN:   sMh         +MMMy---/odMMNds-     dd     /dMMMMo`  MM       +MMMNMMMMN/"
set "#008=%spc%            `hMMMm  /Nm`         +MMMs      -dMMMm     dd      `sMMMMd- MM       +MMMs:NMMMm."
set "#009=%spc%             .NMMMs-NN.          +MMMs       .MMMM    -MN.       -mMMMNsMM       +MMMs .dMMMN/"
set "#010=%spc%              +MMMNNN:           +MMMs       `MMMs    +MM/        `oNMMMMM       +MMMs  `oMMMMs`"
set "#011=%spc%               sMMMM+            +MMMy      `yMN+`   `mMMd`         -dMMMM       +MMMy    /NMMMd/"
set "#012=%spc%               `mMMs          `:omMMMMds+//shh/`    +dMMMMd/         `oNMM    `:omMMMMs/.  .dMMMMmo-"
set "#013=%spc%                .o/           `:::::::::::-`        ::::::::           .yy    `:::::::::.    .:::::."

cls
for /f "tokens=2 delims==" %%a in ('set #0') do echo %%a
pause
set "spc=%spc%      "
goto :loop
pause



batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: center text in a batch file

#4 Post by batchcc » 03 Sep 2015 08:41

Can I just start with the vbnr centered for 1 second then exit rather than having to move it manually

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: center text in a batch file

#5 Post by foxidrive » 03 Sep 2015 14:39

You'll have to explain what you expect on the machines it is going to run on.
What OS, what default cmd window size, if you want the cmd window to be huge etc.

That's because a cmd window can't be set to full screen using the start command in modern windows (but I think it can be in Windows 10), and when you issue the mode 1000 command then two things happen:

1) the screen widens to the full screen width, but the origin point remains where it is,
so the left hand side isn't aligned with the edge of the screen and the right hand hangs over the edge and is invisible.

2) the mode command using mode con /status reports 1000 columns so you can't
determine how wide the window is to be able to calculate the centre position to centre the text.

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: center text in a batch file

#6 Post by batchcc » 04 Sep 2015 05:20

I am using windows vista and the text doesn't have to be centered perfectly just moved over 4 or 5 tab indents.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: center text in a batch file

#7 Post by foxidrive » 04 Sep 2015 07:17

batchcc wrote:I am using windows vista and the text doesn't have to be centered perfectly just moved over 4 or 5 tab indents.


Does it have to be tabs? Can you use spaces?

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: center text in a batch file

#8 Post by batchcc » 05 Sep 2015 15:51

Yes spaces will work as well.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: center text in a batch file

#9 Post by foxidrive » 05 Sep 2015 16:56

Code: Select all

@echo off
mode 1000
set "spc=                                "
set "#001=%spc%        :ooooooo-      +oooooooo:oooooooooooooo/:`    :oooooo:        .oooooooo..oooooooooooooo/-"
set "#002=%spc%      `:yMMMMh`      `-oMMMMo-``-dMMMd:.`-+mMMMN:   ``+NMMMMy.       .hMMMMh.  `-dMMMd:../yMMMMm`"
set "#003=%spc%         sMMMMo         MMN:     +MMMs      dMMMd      dNNMMMm/       `mMMd`     +MMMs    `sMMMM+"
set "#004=%spc%          dMMMN-       +MM:      +MMMs      -MMMs      dd.hMMMMh`      +MM+      +MMMs      MMMM-"
set "#005=%spc%          .mMMMm      .NM+       +MMMs      oMNo       dd  /NMMMN/     -MM.      +MMMs     `MMN/"
set "#006=%spc%           :MMMMs     hMy        +MMMd++++ohmo.        dd   .yMMMMd-    MM       +MMMNo:` :dNs`"
set "#007=%spc%            sMMMN:   sMh         +MMMy---/odMMNds-     dd     /dMMMMo`  MM       +MMMNMMMMN/"
set "#008=%spc%            `hMMMm  /Nm`         +MMMs      -dMMMm     dd      `sMMMMd- MM       +MMMs:NMMMm."
set "#009=%spc%             .NMMMs-NN.          +MMMs       .MMMM    -MN.       -mMMMNsMM       +MMMs .dMMMN/"
set "#010=%spc%              +MMMNNN:           +MMMs       `MMMs    +MM/        `oNMMMMM       +MMMs  `oMMMMs`"
set "#011=%spc%               sMMMM+            +MMMy      `yMN+`   `mMMd`         -dMMMM       +MMMy    /NMMMd/"
set "#012=%spc%               `mMMs          `:omMMMMds+//shh/`    +dMMMMd/         `oNMM    `:omMMMMs/.  .dMMMMmo-"
set "#013=%spc%                .o/           `:::::::::::-`        ::::::::           .yy    `:::::::::.    .:::::."

cls
for /f "tokens=2 delims==" %%a in ('set #0') do echo %%a
pause

Post Reply