See here below a modification of the formatting function following your template.
I added your ASCII example and also my previous unicode example with a mixed types dataframe.
revised code
using DataFrames
# function by @StefanKarpinski (https://discourse.julialang.org/t/truncate-string/27978/14)
slice(s, n, m) = s[max(1, nextind(s, 0, n)):min(end, nextind(s, 0, m))]
function lstr(s)
ls = length(s)
ls ≤ colwidth && return s
return slice(s, 1, colwidth) * "…"
end
function rstr(s)
ls = length(s)
ls ≤ colwidth && return s
return "…" * slice(s, max(1, ls - colwidth + 1), ls)
end
function cstr(s)
ls = length(s)
ls ≤ colwidth && return s
r1 = slice(s, 1, colwidth÷2)
r2 = colwidth÷2 ≥ ls ? "" : slice(s, max(1, ls - colwidth÷2 + 1), ls)
return r1 * "…" * r2
end
# Example#1
df = DataFrame(strings = ["0123456789", join('a':'z'), "short"])
colwidth = 10
colswidths = [colwidth + 3]
textcols = names(df, String)
show(transform(df, textcols .=> ByRow(lstr); renamecols=false), alignment=:l, columns_width=colswidths)
show(transform(df, textcols .=> ByRow(rstr); renamecols=false), alignment=:l, columns_width=colswidths)
show(transform(df, textcols .=> ByRow(cstr); renamecols=false), alignment=:l, columns_width=colswidths)
# Example#2
df = DataFrame(strings = [join('α':'ω'), join('a':'z')])
df.length = length.(df.strings)
colwidth = 11 # try also: 30
colswidths = [colwidth + 3, 7]
textcols = names(df, String)
show(transform(df, textcols .=> ByRow(lstr); renamecols=false), alignment=:l, columns_width=colswidths)
show(transform(df, textcols .=> ByRow(rstr); renamecols=false), alignment=:r, columns_width=colswidths)
show(transform(df, textcols .=> ByRow(cstr); renamecols=false), alignment=:c, columns_width=colswidths)