master.lib's text_boxfillca() function would have been perfectly suitable here… Part of P0089, funded by [Anonymous] and Blue Bolt.